Skip to content

Commit

Permalink
feat: add new endpoint and improve middleware functionality
Browse files Browse the repository at this point in the history
- 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 <[email protected]>
  • Loading branch information
appleboy committed Jan 27, 2025
1 parent e389346 commit bc3ccd1
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion _example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,22 @@ import (

func main() {
r := gin.Default()
r.Use(gzip.Gzip(gzip.DefaultCompression))
r.Use(gzip.Gzip(
gzip.DefaultCompression,
gzip.WithExcludedPaths([]string{"/ping2"}),
))
r.Use(func(c *gin.Context) {
log.Println("Request received")
c.Next()
log.Println("Response sent")
})

r.GET("/ping", func(c *gin.Context) {
c.String(http.StatusOK, "pong "+fmt.Sprint(time.Now().Unix()))
})
r.GET("/ping2", func(c *gin.Context) {
c.String(http.StatusOK, "pong "+fmt.Sprint(time.Now().Unix()))
})
r.GET("/stream", func(c *gin.Context) {
c.Header("Content-Type", "text/event-stream")
c.Header("Connection", "keep-alive")
Expand Down

0 comments on commit bc3ccd1

Please sign in to comment.