1 Star 0 Fork 0

Wsage/go-framework

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
server_http_middlerware.go 500 Bytes
一键复制 编辑 原始数据 按行查看 历史
王少奇 提交于 2021-08-11 15:12 . 优化 response
package httpserver
type Middleware func(ctx *Ctx, next func(ctx *Ctx))
//处理中间件
var handlerMiddleware = func(f HttpRouteFunc, middleware []Middleware) func(ctx *Ctx) {
funcArr := []func(*Ctx){}
funcArr = append(funcArr, func(ctx *Ctx) {
f(ctx)
})
//新增中间件的处理
j := 0
for i := len(middleware) - 1; i >= 0; i-- {
index := i
t := j
funcArr = append(funcArr, func(ctx *Ctx) {
middleware[index](ctx, funcArr[t])
})
j++
}
return funcArr[len(funcArr)-1]
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/scottq/go-framework.git
git@gitee.com:scottq/go-framework.git
scottq
go-framework
go-framework
v1.1.19

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385