File tree 2 files changed +88
-0
lines changed
2 files changed +88
-0
lines changed Original file line number Diff line number Diff line change @@ -201,3 +201,56 @@ func main() {
201
201
}
202
202
}
203
203
```
204
+
205
+ ## Custom ` SkipPathRegexps ` function
206
+
207
+ Example for custom ` SkipPathRegexps ` function
208
+
209
+ ``` go
210
+ rxURL := regexp.MustCompile (` ^/ping\s*` )
211
+ r.Use (ginzap.GinzapWithConfig (logger, &ginzap.Config {
212
+ UTC : true ,
213
+ TimeFormat : time.RFC3339 ,
214
+ SkipPathRegexps : []*regexp.Regexp {rxURL},
215
+ }))
216
+ ```
217
+
218
+ Full example
219
+
220
+ ``` go
221
+ package main
222
+
223
+ import (
224
+ " fmt"
225
+ " regexp"
226
+ " time"
227
+
228
+ ginzap " github.com/gin-contrib/zap"
229
+
230
+ " github.com/gin-gonic/gin"
231
+ " go.uber.org/zap"
232
+ )
233
+
234
+ func main () {
235
+ r := gin.New ()
236
+
237
+ logger , _ := zap.NewProduction ()
238
+ rxURL := regexp.MustCompile (` ^/ping\s*` )
239
+
240
+ r.Use (ginzap.GinzapWithConfig (logger, &ginzap.Config {
241
+ UTC: true ,
242
+ TimeFormat: time.RFC3339 ,
243
+ SkipPathRegexps: []*regexp.Regexp {rxURL},
244
+ }))
245
+
246
+ // Example ping request.
247
+ r.GET (" /ping1234" , func (c *gin.Context ) {
248
+ c.String (200 , " pong " +fmt.Sprint (time.Now ().Unix ()))
249
+ })
250
+
251
+ // Listen and Server in 0.0.0.0:8080
252
+ if err := r.Run (" :8080" ); err != nil {
253
+ panic (err)
254
+ }
255
+ }
256
+ ```
Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import (
4
+ "fmt"
5
+ "regexp"
6
+ "time"
7
+
8
+ ginzap "github.com/gin-contrib/zap"
9
+
10
+ "github.com/gin-gonic/gin"
11
+ "go.uber.org/zap"
12
+ )
13
+
14
+ func main () {
15
+ r := gin .New ()
16
+
17
+ logger , _ := zap .NewProduction ()
18
+ rxURL := regexp .MustCompile (`^/ping\s*` )
19
+
20
+ r .Use (ginzap .GinzapWithConfig (logger , & ginzap.Config {
21
+ UTC : true ,
22
+ TimeFormat : time .RFC3339 ,
23
+ SkipPathRegexps : []* regexp.Regexp {rxURL },
24
+ }))
25
+
26
+ // Example ping request.
27
+ r .GET ("/ping1234" , func (c * gin.Context ) {
28
+ c .String (200 , "pong " + fmt .Sprint (time .Now ().Unix ()))
29
+ })
30
+
31
+ // Listen and Server in 0.0.0.0:8080
32
+ if err := r .Run (":8080" ); err != nil {
33
+ panic (err )
34
+ }
35
+ }
You can’t perform that action at this time.
0 commit comments