package main import( "net/http" "github.com/gin-gonic/gin" "time" "log" ) func Logger() gin.HandlerFunc { return func(c *gin.Context){ t:=time.Now() c.Set("example", "12345") c.Next() latency:=time.Since(t) log.Print(latency) status:=c.Writer.Status() log.Println(status) } } func main(){ r:=gin.Default() r.Use(Logger()) r.GET("/ping", func(c *gin.Context){ c.JSON(http.StatusOK, gin.H{ "message":"pong", "amount": 3, }) }) r.GET("/test", func(c *gin.Context){ example:=c.MustGet("example").(string) log.Println(example) }) r.Run() }