func main() { // Echo instance e := vodka.New() // Debug mode e.Debug() //------------ // Middleware //------------ // Logger e.Use(mw.Logger()) // Recover e.Use(mw.Recover()) // Basic auth e.Use(mw.BasicAuth(func(usr, pwd string) bool { if usr == "joe" && pwd == "secret" { return true } return false })) // Gzip e.Use(mw.Gzip()) // Routes e.Get("/", hello) // Start server e.Run(":1323") }
func main() { v := vodka.New() v.Use(m.Logger()) v.Use(m.Recover()) v.Use(m.Gzip()) v.GET("/", HelloHandler) v.Run(fasthttp.New(":1987")) }
func createMux() *vodka.Vodka { e := vodka.New() e.Use(middleware.Recover()) e.Use(middleware.Logger()) e.Use(middleware.Gzip()) e.Use(middleware.Static("public")) return e }
func main() { v := vodka.New() store := sessions.NewCookieStore() v.Use(sessions.Sessions("vodka", store)) v.Use(m.Logger()) v.Use(m.Recover()) v.Use(m.Gzip()) v.Static("/static/", "static") v.Favicon("static/ico/favicon.ico") v.SetRenderer(pongor.Renderor()) g := v.Group("") g.Get("/", handler.MainHandler) g.Get("/signup/", handler.SignupGetHandler) g.Post("/signup/", handler.SignupPostHandler) g.Get("/signin/", handler.SigninGetHandler) g.Post("/signin/", handler.SigninPostHandler) g.Get("/signout/", handler.SignoutHandler) g.Any("/search/", handler.SearchHandler) g.Get("/node/:nid/", handler.NodeHandler) g.Get("/view/:tid/", handler.ViewHandler) g.Get("/category/:cid/", handler.MainHandler) // Restricted group r := v.Group("") jwt.JWTContextKey = key jwt.Bearer = "Zenpress" r.Use(jwt.JWTAuther(jwt.Options{ KeyFunc: func(ctx *vodka.Context) (string, error) { return jwt.JWTContextKey, nil }, })) r.Get("/new/category/", handler.NewCategoryGetHandler) r.Post("/new/category/", handler.NewCategoryPostHandler) r.Get("/new/node/", handler.NewNodeGetHandler) r.Post("/new/node/", handler.NewNodePostHandler) r.Get("/new/topic/", handler.NewTopicGetHandler) r.Post("/new/topic/", handler.NewTopicPostHandler) r.Post("/new/reply/:tid/", handler.NewReplyPostHandler) r.Get("/modify/category/", handler.ModifyCatGetHandler) r.Post("/modify/category/", handler.ModifyCatPostHandler) r.Get("/modify/node/", handler.ModifyNodeGetHandler) r.Post("/modify/node/", handler.ModifyNodePostHandler) r.Any("/topic/delete/:tid/", handler.TopicDeleteHandler) r.Get("/topic/edit/:tid/", handler.TopicEditGetHandler) r.Post("/topic/edit/:tid/", handler.TopicEditPostHandler) r.Any("/node/delete/:nid/", handler.NodeDeleteHandler) r.Get("/node/edit/:nid/", handler.NodeEditGetHandler) r.Post("/node/edit/:nid/", handler.NodeEditPostHandler) r.Any("/delete/reply/:rid/", handler.DeleteReplyHandler) //hotness r.Any("/like/:name/:id/", handler.LikeHandler) r.Any("/hate/:name/:id/", handler.HateHandler) // e.g. /debug/pprof, /debug/pprof/heap, etc. vodkapprof.Wrapper(v) v.Run(9000) }
func main() { e := vodka.New() // Middleware e.Use(mw.Logger()) e.Use(mw.Recover()) e.Use(mw.Gzip()) //------------------------ // Third-party middleware //------------------------ // https://github.com/rs/cors e.Use(cors.Default().Handler) // https://github.com/thoas/stats s := stats.New() e.Use(s.Handler) // Route e.Get("/stats", func(c *vodka.Context) error { return c.JSON(http.StatusOK, s.Data()) }) // Serve index file e.Index("public/index.html") // Serve favicon e.Favicon("public/favicon.ico") // Serve static files e.Static("/scripts", "public/scripts") //-------- // Routes //-------- e.Post("/users", createUser) e.Get("/users", getUsers) e.Get("/users/:id", getUser) //----------- // Templates //----------- t := &Template{ // Cached templates templates: template.Must(template.ParseFiles("public/views/welcome.html")), } e.SetRenderer(t) e.Get("/welcome", welcome) //------- // Group //------- // Group with parent middleware a := e.Group("/admin") a.Use(func(c *vodka.Context) error { // Security middleware return nil }) a.Get("", func(c *vodka.Context) error { return c.String(http.StatusOK, "Welcome admin!") }) // Group with no parent middleware g := e.Group("/files", func(c *vodka.Context) error { // Security middleware return nil }) g.Get("", func(c *vodka.Context) error { return c.String(http.StatusOK, "Your files!") }) // Start server e.Run(":1323") }