mirror of
https://github.com/infinite-iroha/touka.git
synced 2026-02-03 00:41:10 +08:00
update UseIf
This commit is contained in:
parent
53544644af
commit
21d048b5ab
1 changed files with 13 additions and 2 deletions
15
midware_x.go
15
midware_x.go
|
|
@ -1,9 +1,9 @@
|
||||||
package touka
|
package touka
|
||||||
|
|
||||||
// UseIf 是一个条件中间件包装器。
|
// UseChainIf 是一个条件中间件包装器。
|
||||||
// 如果 `condition` 为 true,它将执行提供的 `middlewares` 链。
|
// 如果 `condition` 为 true,它将执行提供的 `middlewares` 链。
|
||||||
// 如果 `condition` 为 false,它会直接跳过这些中间件,调用下一个处理器。
|
// 如果 `condition` 为 false,它会直接跳过这些中间件,调用下一个处理器。
|
||||||
func (engine *Engine) UseIf(condition bool, middlewares ...HandlerFunc) HandlerFunc {
|
func (engine *Engine) UseChainIf(condition bool, middlewares ...HandlerFunc) HandlerFunc {
|
||||||
if !condition {
|
if !condition {
|
||||||
return func(c *Context) {
|
return func(c *Context) {
|
||||||
c.Next()
|
c.Next()
|
||||||
|
|
@ -38,3 +38,14 @@ func (engine *Engine) UseIf(condition bool, middlewares ...HandlerFunc) HandlerF
|
||||||
c.Next()
|
c.Next()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UseIf 是一个条件中间件包装器
|
||||||
|
func (engine *Engine) UseIf(condition bool, middlewares HandlerFunc) HandlerFunc {
|
||||||
|
if !condition {
|
||||||
|
return func(c *Context) {
|
||||||
|
c.Next()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return middlewares
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue