package main
import (
"github.com/gin-gonic/gin"
"log"
"time"
)
func Logger() gin. HandlerFunc {
return func(context *gin.Context) {
t := time. Now()
// set variables
context. Set("example", 123456)
context.Next() // Request front and rear dividing lines
latency := time. Since(t)
log.Println(latency) // request time
status := context. Writer. Status()
log.Println(status) // response status code
}
}
func main() {
router := gin. New()
router. Use(Logger())
router.GET("/", func(context *gin.Context) {
example := context.MustGet("example").(int)
log.Println(example)
context. String(200, "ookk")
})
router. Run()
}