Example #1
0
func main() {
	r := gin.Default()

	store := cache.NewInMemoryStore(time.Second)
	// Cached Page
	r.GET("/ping", func(c *gin.Context) {
		c.String(200, "pong "+fmt.Sprint(time.Now().Unix()))
	})

	r.GET("/cache_ping", cache.CachePage(store, time.Minute, func(c *gin.Context) {
		c.String(200, "pong "+fmt.Sprint(time.Now().Unix()))
	}))

	// Listen and Server in 0.0.0.0:8080
	r.Run(":8080")
}
Example #2
0
File: gin.go Project: SlinSo/egon
func mainGin() {
	r := gin.Default()
	r.GET("/hello", func(c *gin.Context) {
		u := &model.User{}
		c.Status(200)
		c.Writer.Header()["Content-Type"] = []string{"text/html; charset=utf-8"}

		SimpleTemplate(c.Writer, u)
	})

	// caching can still happen in middleware
	store := cache.NewInMemoryStore(time.Second)
	r.GET("/hello_cache", cache.CachePage(store, time.Minute, func(c *gin.Context) {
		u := &model.User{}
		c.Status(200)
		c.Writer.Header()["Content-Type"] = []string{"text/html; charset=utf-8"}

		SimpleTemplate(c.Writer, u)
	}))
	r.Run()
}