示例#1
0
文件: main.go 项目: kellegous/404
func main() {
	flagAddr := flag.String("addr", ":8080", "")
	flagConf := flag.String("conf", "config.json", "")
	flag.Parse()

	var cfg config.Config
	if err := cfg.LoadFromFile(*flagConf); err != nil {
		panic(err)
	}

	ctx, err := context.Open(&cfg)
	if err != nil {
		panic(err)
	}

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

	debug.Setup(r)
	auth.Setup(r, ctx)

	if err := hub.Setup(r, ctx); err != nil {
		panic(err)
	}

	if err := setup(r, ctx); err != nil {
		panic(err)
	}

	if err := http.ListenAndServe(*flagAddr, r); err != nil {
		panic(err)
	}
}
示例#2
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)
	}
}
示例#3
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)
	}
}
示例#4
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)
	}
}
示例#5
0
文件: pork-cli.go 项目: progers/pork
func main() {
	addr := flag.String("addr", ":6080", "The address to use")
	flag.Parse()

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

	// setup a simple router
	r := pork.NewRouter(func(status int, r *http.Request) {
		log.Printf("%d %s %s %s", status, r.RemoteAddr, r.Method, r.URL.String())
	}, nil, nil)
	r.Handle("/", pork.Content(pork.None, dirs...))
	http.ListenAndServe(*addr, r)
}
示例#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)
	}
}