Example #1
0
func main() {
	configPath := flag.String("c", "./config.json", "-c=./config.json")
	outBuildInfo := flag.Bool("v", false, "build info")
	help := flag.Bool("h", false, "help")
	flag.Parse()

	if *help {
		flag.Usage()
		return
	}

	if *outBuildInfo {
		outputBuildInfo()
		return
	}

	loadConfig(*configPath)
	initLog()

	app := app.New()
	s := stats.New()
	app.Use(NewLogMiddle(s))
	app.Use(mount.New("/file", NewStaticServeMiddle("/file", config.StaticDir)))
	registRouter(app)

	go s.TickEveryTo(time.Second*60, logger)

	err := startServer(app)
	if err != nil {
		logger.Printf(" %v", err)
	}
}
Example #2
0
func registRouter(app *app.App) {
	app.Use(mount.New("/v1", http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
		resp.Write([]byte("/v1"))
	})))
	app.Get("/", http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
		resp.Write([]byte("ok"))
	}))

	app.Get("/debug/_gom", gomhttp.Handler())
}