Skip to content

Instantly share code, notes, and snippets.

@tanapoln
Last active September 15, 2020 15:57
Show Gist options
  • Save tanapoln/8e5711b91f96ee10658a9064c88bca66 to your computer and use it in GitHub Desktop.
Save tanapoln/8e5711b91f96ee10658a9064c88bca66 to your computer and use it in GitHub Desktop.
Simple page view counter
package main
import (
"fmt"
"github.com/gin-gonic/gin"
)
func main() {
counter := 0
r := gin.Default()
r.GET("/", func(c *gin.Context) {
counter++
c.String(200, "Hello world")
})
r.GET("/stats", func(c *gin.Context) {
c.String(200, fmt.Sprintf("Number of page view: %d", counter))
})
r.Run()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment