From 21d048b5ab17af3adff24169720c4977caa3d638 Mon Sep 17 00:00:00 2001 From: wjqserver <114663932+WJQSERVER@users.noreply.github.com> Date: Tue, 17 Jun 2025 14:34:52 +0800 Subject: [PATCH] update UseIf --- midware_x.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/midware_x.go b/midware_x.go index 4e28f9b..073a03c 100644 --- a/midware_x.go +++ b/midware_x.go @@ -1,9 +1,9 @@ package touka -// UseIf 是一个条件中间件包装器。 +// UseChainIf 是一个条件中间件包装器。 // 如果 `condition` 为 true,它将执行提供的 `middlewares` 链。 // 如果 `condition` 为 false,它会直接跳过这些中间件,调用下一个处理器。 -func (engine *Engine) UseIf(condition bool, middlewares ...HandlerFunc) HandlerFunc { +func (engine *Engine) UseChainIf(condition bool, middlewares ...HandlerFunc) HandlerFunc { if !condition { return func(c *Context) { c.Next() @@ -38,3 +38,14 @@ func (engine *Engine) UseIf(condition bool, middlewares ...HandlerFunc) HandlerF c.Next() } } + +// UseIf 是一个条件中间件包装器 +func (engine *Engine) UseIf(condition bool, middlewares HandlerFunc) HandlerFunc { + if !condition { + return func(c *Context) { + c.Next() + } + } + + return middlewares +}