-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: improve documentation and add example code
- Add a custom `SkipPathRegexps` function to the README.md file - Include an example for the custom function in the README.md file - Add a new file `_example/example04/main.go` with similar content to the README.md file Signed-off-by: appleboy <[email protected]>
- Loading branch information
Showing
2 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
"time" | ||
|
||
ginzap "github.com/gin-contrib/zap" | ||
|
||
"github.com/gin-gonic/gin" | ||
"go.uber.org/zap" | ||
) | ||
|
||
func main() { | ||
r := gin.New() | ||
|
||
logger, _ := zap.NewProduction() | ||
rxURL := regexp.MustCompile(`^/ping\s*`) | ||
|
||
r.Use(ginzap.GinzapWithConfig(logger, &ginzap.Config{ | ||
UTC: true, | ||
TimeFormat: time.RFC3339, | ||
SkipPathRegexps: []*regexp.Regexp{rxURL}, | ||
})) | ||
|
||
// Example ping request. | ||
r.GET("/ping1234", func(c *gin.Context) { | ||
c.String(200, "pong "+fmt.Sprint(time.Now().Unix())) | ||
}) | ||
|
||
// Listen and Server in 0.0.0.0:8080 | ||
if err := r.Run(":8080"); err != nil { | ||
panic(err) | ||
} | ||
} |