Skip to content

Commit 1bdc1f7

Browse files
committed
feat: convert go-zero middleware to gin
1 parent 1deb9fc commit 1bdc1f7

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

router/gin/middleware.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package gin
2+
3+
import (
4+
"net/http"
5+
6+
"github.com/gin-gonic/gin"
7+
)
8+
9+
type (
10+
Middleware func(next http.Handler) http.Handler
11+
)
12+
13+
func HandlerFunc(ctx *gin.Context) http.HandlerFunc {
14+
return func(w http.ResponseWriter, r *http.Request) {
15+
ctx.Request = r
16+
ctx.Next()
17+
}
18+
}
19+
20+
func ZeroMiddleware(middleware Middleware) func(ctx *gin.Context) {
21+
return func(ctx *gin.Context) {
22+
next := HandlerFunc(ctx)
23+
middleware(next).ServeHTTP(ctx.Writer, ctx.Request)
24+
}
25+
}

0 commit comments

Comments
 (0)