添加example&优化参数截取

This commit is contained in:
Yun
2024-07-09 16:35:14 +08:00
parent 70699e9701
commit 1abd260929
3 changed files with 64 additions and 20 deletions
+29
View File
@@ -0,0 +1,29 @@
package main
import (
"context"
"github.com/gin-gonic/gin"
"github.com/yuninks/loggerx"
"github.com/yuninks/loggerx/middleware"
)
// curl --location '127.0.0.1:8080/ping'
func main() {
ctx := context.Background()
log := loggerx.NewLogger(ctx, loggerx.SetToConsole())
g := gin.Default()
g.Use(middleware.SetGinTraceIdByLogger(log))
g.Use(middleware.SetGinParams(log))
g.GET("/ping", func(ctx *gin.Context) {
log.Infof(ctx, "GET /ping")
ctx.JSON(200, gin.H{"message": "pong"})
})
g.Run(":8080")
}