Esempio n. 1
0
func main() {
	v := vodka.New()
	v.Use(middleware.Logger())
	v.Use(middleware.Recover())
	r := pongor.Renderor()
	v.SetRenderer(r)
	v.Static("/static", "static")
	v.Get("/", func(ctx vodka.Context) error {
		var data = make(map[string]interface{})
		data["name"] = "Insion Ng"
		ctx.SetStore(data)

		ctx.SetStore(map[string]interface{}{
			"title": "你好,世界",
			"oh":    "no",
		})
		ctx.Set("oh", "yes") //覆盖前面指定KEY
		return ctx.Render(200, "index")
	})

	v.Run(fasthttp.New(":9000"))
}
Esempio n. 2
0
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)
}