Beispiel #1
0
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"))
}
Beispiel #2
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"))
}
Beispiel #3
0
func main() {

	v := vodka.New()
	v.Use(cache.Cacher(cache.Options{Adapter: "redis", AdapterConfig: `{"Addr":":6379"}`, Section: "test", Interval: 5}))

	v.GET("/cache/put/", func(self vodka.Context) error {
		err := cache.Store(self).Set("name", "vodka", 60)
		if err != nil {
			return err
		}

		return self.String(http.StatusOK, "store okay")
	})

	v.GET("/cache/get/", func(self vodka.Context) error {
		var name string
		cache.Store(self).Get("name", &name)

		return self.String(http.StatusOK, fmt.Sprintf("get name %s", name))
	})

	v.Run(fasthttp.New(":7891"))
}