func main() { runtime.GOMAXPROCS(runtime.NumCPU()) fetchFeed() e := echo.New() e.Use(mw.Logger()) e.Use(mw.Recover()) e.Use(mw.StripTrailingSlash()) e.Use(mw.Gzip()) e.Use(cors.Default().Handler) bundle, _ := ioutil.ReadFile("./build/bundle.js") // stats s := stats.New() e.Use(s.Handler) e.Get("/stats", func(c *echo.Context) error { return c.JSON(http.StatusOK, s.Data()) }) // static files e.Static("/public/css", "public/css") e.Static("/universal.js", "./build/bundle.js") e.Favicon("public/favicon.ico") e.Get("/", selfjs.New(runtime.NumCPU(), string(bundle), rss)) e.Get("/about", selfjs.New(runtime.NumCPU(), string(bundle), loremJSON())) e.Get("/api/data", apiFrontPage) e.Get("/api/anotherpage", apiAnotherPage) go tick() fmt.Println("serving at port 3000") e.Run(":3000") }
func main() { fromEmail = os.Getenv("FROMEMAIL") emailSendingPasswd = os.Getenv("EMAILSENDINGPASSWD") if fromEmail == "" || emailSendingPasswd == "" { log.Fatal("FROMEMAIL or EMAILSENDINGPASSWD was not set") } runtime.GOMAXPROCS(runtime.NumCPU()) app := NewApplication() app.Init() e := echo.New() e.Use(middleware.HttpLogger()) e.HTTP2() e.SetHTTPErrorHandler(app.errorHandler) e.Use(mw.Recover()) e.Use(mw.Gzip()) e.StripTrailingSlash() e.Use(cors.Default().Handler) /* TODO: logs too much newrelickey, found := os.LookupEnv("NEWRELICKEY") if found == true { gorelic.InitNewRelicAgent(newrelickey, "go-register-login", true) e.Use(gorelic.Handler()) } */ s := stats.New() e.Use(s.Handler) e.Get("/stats", func(c *echo.Context) error { return c.JSON(http.StatusOK, s.Data()) }) e.Favicon("public/favicon.ico") e.Static("/public/css", "public/css") e.Static("/universal.js", "./build/bundle.js") bundle, _ := ioutil.ReadFile("./build/bundle.js") user, _ := json.Marshal(domain.User{}) e.Get("/", selfjs.New(runtime.NumCPU(), string(bundle), string(user))) e.Get("/register", selfjs.New(runtime.NumCPU(), string(bundle), string(user))) e.Get("/login", selfjs.New(runtime.NumCPU(), string(bundle), string(user))) admin := e.Group("/members") admin.Use(middleware.CheckAdmin(app.Redis, string(bundle))) admin.Get("", selfjs.New(runtime.NumCPU(), string(bundle), app.listUsers())) e.Get("/api/users", app.listUsersAPI) e.Get("/api/user/:id", app.userAPI) e.Get("/verify/:id/:hash", app.verifyEmail) e.Post("/register", app.createUser) e.Get("/logout", app.logout) e.Post("/login", app.login) fmt.Println("Starting server at port 3300") e.Run(":3300") }