Skip to content

Commit bc3ccd1

Browse files
committed
feat: add new endpoint and improve middleware functionality
- Modify gzip middleware to exclude `/ping2` path - Add middleware to log request and response times - Add new endpoint `/ping2` that returns current Unix timestamp Signed-off-by: appleboy <appleboy.tw@gmail.com>
1 parent e389346 commit bc3ccd1

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

_example/main.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,22 @@ import (
1212

1313
func main() {
1414
r := gin.Default()
15-
r.Use(gzip.Gzip(gzip.DefaultCompression))
15+
r.Use(gzip.Gzip(
16+
gzip.DefaultCompression,
17+
gzip.WithExcludedPaths([]string{"/ping2"}),
18+
))
19+
r.Use(func(c *gin.Context) {
20+
log.Println("Request received")
21+
c.Next()
22+
log.Println("Response sent")
23+
})
24+
1625
r.GET("/ping", func(c *gin.Context) {
1726
c.String(http.StatusOK, "pong "+fmt.Sprint(time.Now().Unix()))
1827
})
28+
r.GET("/ping2", func(c *gin.Context) {
29+
c.String(http.StatusOK, "pong "+fmt.Sprint(time.Now().Unix()))
30+
})
1931
r.GET("/stream", func(c *gin.Context) {
2032
c.Header("Content-Type", "text/event-stream")
2133
c.Header("Connection", "keep-alive")

0 commit comments

Comments
 (0)