Skip to content

Commit

Permalink
feat: convert go-zero middleware to gin
Browse files Browse the repository at this point in the history
  • Loading branch information
WqyJh committed May 23, 2024
1 parent 1deb9fc commit 1bdc1f7
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions router/gin/middleware.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package gin

import (
"net/http"

"github.com/gin-gonic/gin"
)

type (
Middleware func(next http.Handler) http.Handler
)

func HandlerFunc(ctx *gin.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx.Request = r
ctx.Next()
}
}

func ZeroMiddleware(middleware Middleware) func(ctx *gin.Context) {
return func(ctx *gin.Context) {
next := HandlerFunc(ctx)
middleware(next).ServeHTTP(ctx.Writer, ctx.Request)
}
}

0 comments on commit 1bdc1f7

Please sign in to comment.