Skip to content

Commit

Permalink
docs: enhance skipper documentation and simplify examples
Browse files Browse the repository at this point in the history
- Add examples of skipper usage in both README.md and _example/main.go, including GET and POST methods for `/ping` endpoint with dynamic responses.
- Remove the toolchain specification from _example/go.mod.

Signed-off-by: Bo-Yi Wu <[email protected]>
  • Loading branch information
appleboy committed May 9, 2024
1 parent 8db09f4 commit 904b080
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,20 @@ func main() {
c.String(http.StatusOK, "pong "+fmt.Sprint(time.Now().Unix()))
})

// Example of skipper usage
v1 := r.Group("/v1", logger.SetLogger(
logger.WithSkipper(func(c *gin.Context) bool {
return c.Request.Method == "GET"
})))
{
v1.GET("/ping", func(c *gin.Context) {
c.String(http.StatusOK, "pong01 "+fmt.Sprint(time.Now().Unix()))
})
v1.POST("/ping", func(c *gin.Context) {
c.String(http.StatusOK, "pong02 "+fmt.Sprint(time.Now().Unix()))
})
}

// Listen and Server in 0.0.0.0:8080
if err := r.Run(":8080"); err != nil {
log.Fatal().Msg("can' start server with 8080 port")
Expand Down
2 changes: 0 additions & 2 deletions _example/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ module test

go 1.21

toolchain go1.21.4

require (
github.com/gin-contrib/logger v0.2.6
github.com/gin-contrib/requestid v1.0.0
Expand Down
14 changes: 14 additions & 0 deletions _example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,20 @@ func main() {
c.String(http.StatusOK, "pong "+fmt.Sprint(time.Now().Unix()))
})

// Example of skipper usage
v1 := r.Group("/v1", logger.SetLogger(
logger.WithSkipper(func(c *gin.Context) bool {
return c.Request.Method == "GET"
})))
{
v1.GET("/ping", func(c *gin.Context) {
c.String(http.StatusOK, "pong01 "+fmt.Sprint(time.Now().Unix()))
})
v1.POST("/ping", func(c *gin.Context) {
c.String(http.StatusOK, "pong02 "+fmt.Sprint(time.Now().Unix()))
})
}

// Listen and Server in 0.0.0.0:8080
if err := r.Run(":8080"); err != nil {
log.Fatal().Msg("can' start server with 8080 port")
Expand Down

0 comments on commit 904b080

Please sign in to comment.