예제 #1
0
func main() {
	flagWork := flag.String("work", "work", "")
	flagAddr := flag.String("addr", ":4020", "")
	flag.Parse()

	root, err := rootPath()
	if err != nil {
		panic(err)
	}

	r := pork.NewRouter(
		func(status int, r *http.Request) {
			log.Printf("%d - %s", status, r.URL.Path)
		}, nil, nil)

	r.RespondWith("/", pork.Content(pork.NewConfig(pork.None),
		http.Dir(filepath.Join(root, "src/pub"))))
	r.RespondWith("/data/", pork.Content(pork.NewConfig(pork.None),
		http.Dir(*flagWork)))

	log.Printf("Server running on address %s\n", *flagAddr)
	if err := http.ListenAndServe(*flagAddr, r); err != nil {
		panic(err)
	}
}
예제 #2
0
파일: main.go 프로젝트: kellegous/404
func setup(r pork.Router, ctx *context.Context) error {
	root, err := findRoot()
	if err != nil {
		return err
	}

	c := pork.Content(pork.NewConfig(pork.None),
		http.Dir(root))

	// serves up static content
	r.RespondWithFunc("/", func(w pork.ResponseWriter, r *http.Request) {
		_, err := auth.SessionFromRequest(ctx, r)
		if err != nil {
			http.Redirect(w, r, "/auth/a", http.StatusTemporaryRedirect)
			return
		}

		c.ServePork(w, r)
	})

	// some debugging handlers
	r.RespondWithFunc("/info", func(w pork.ResponseWriter, r *http.Request) {
		sess, user, err := auth.UserFromRequest(ctx, r)
		if err != nil {
			panic(err)
		}

		fmt.Fprintln(w, sess, user)
	})

	return nil
}
예제 #3
0
파일: pork.go 프로젝트: kellegous/pork
func mainBuild(args []string) {
	flags := flag.NewFlagSet("", flag.ExitOnError)
	flagOut := flags.String("out", "", "")
	flagOpt := flags.String("opt", "None", "")
	flags.Parse(args)

	lvl, err := parseOptimization(*flagOpt)
	if err != nil {
		fmt.Fprintf(os.Stderr, "invalid optimization level: %s\n", *flagOpt)
	}

	var dirs []http.Dir
	if flags.NArg() == 0 {
		dirs = append(dirs, http.Dir("."))
	} else {
		for _, arg := range flags.Args() {
			dirs = append(dirs, http.Dir(arg))
		}
	}

	for _, dir := range dirs {
		out := dir
		if *flagOut != "" {
			out = http.Dir(*flagOut)
		}

		if _, err := pork.Content(pork.NewConfig(lvl), dir).Productionize(out); err != nil {
			log.Panic(err)
		}
	}
}
예제 #4
0
파일: serve.go 프로젝트: kellegous/grund
func main() {
	flagAddr := flag.String("addr", ":2018", "")
	flagData := flag.String("data", "data", "")
	flagProd := flag.Bool("prod", false, "")

	flag.Parse()

	if _, err := os.Stat(*flagData); err != nil {
		if err := os.MkdirAll(*flagData, os.ModePerm); err != nil {
			panic(err)
		}
	}

	root, err := rootPath()
	if err != nil {
		panic(err)
	}

	pub := filepath.Join(root, "pub")
	c := pork.Content(pork.NewConfig(pork.None), http.Dir(pub))

	if *flagProd {
		t, err := ioutil.TempDir(os.TempDir(), "grund-")
		if err != nil {
			panic(err)
		}

		if _, err := c.Productionize(http.Dir(t)); err != nil {
			panic(err)
		}

		return
	}

	r := pork.NewRouter(
		func(status int, r *http.Request) {
			log.Printf("%d - %s", status, r.URL.Path)
		}, nil, nil)

	r.Handle("/", &handler{
		c: c,
		t: filepath.Join(root, "index.tpl.html"),
		d: pub,
	})

	setup(*flagData, r)
	if err := http.ListenAndServe(*flagAddr, r); err != nil {
		panic(err)
	}
}
예제 #5
0
func main() {
	flagAddr := flag.String("addr", ":8080", "")
	flag.Parse()

	root, err := findRoot()
	if err != nil {
		panic(err)
	}

	fmt.Printf("root = %s\n", root)

	r := pork.NewRouter(nil, nil, nil)

	r.RespondWith("/", pork.Content(pork.NewConfig(pork.None),
		http.Dir(filepath.Join(root, "src/pub"))))

	if err := http.ListenAndServe(*flagAddr, r); err != nil {
		panic(err)
	}
}
예제 #6
0
파일: pork.go 프로젝트: donjaime/pork
func main() {
	flagAddr := flag.String("addr", ":8082", "address to bind")

	flag.Parse()

	var dirs []http.Dir
	if flag.NArg() == 0 {
		dirs = append(dirs, http.Dir("."))
	} else {
		for _, arg := range flag.Args() {
			dirs = append(dirs, http.Dir(arg))
		}
	}

	r := pork.NewRouter(func(status int, r *http.Request) {
		log.Printf("[%d] %s", status, r.RequestURI)
	}, nil, nil)
	r.Handle("/", pork.Content(pork.NewConfig(pork.None), dirs...))

	if err := http.ListenAndServe(*flagAddr, r); err != nil {
		log.Panic(err)
	}
}