1 Star 0 Fork 0

崔俊 / iris_v1111

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
chained.go 975 Bytes
一键复制 编辑 原始数据 按行查看 历史
崔俊 提交于 2024-03-11 14:05 . first commit
package rule
import (
"github.com/kataras/iris/context"
)
// chainedRule is a Rule with next Rule
type chainedRule struct {
Rule
next Rule
}
var _ Rule = &chainedRule{}
// chainedSingle returns a new rule witch has a next rule too
func chainedSingle(rule Rule, next Rule) Rule {
if next == nil {
next = Satisfied()
}
return &chainedRule{
Rule: rule,
next: next,
}
}
// Chained returns a new rule which has more than one coming next ruleset
func Chained(rule Rule, next ...Rule) Rule {
if len(next) == 0 {
return chainedSingle(rule, nil)
}
c := chainedSingle(rule, next[0])
for i := 1; i < len(next); i++ {
c = chainedSingle(c, next[i])
}
return c
}
// Claim validator
func (c *chainedRule) Claim(ctx context.Context) bool {
if !c.Rule.Claim(ctx) {
return false
}
return c.next.Claim(ctx)
}
// Valid validator
func (c *chainedRule) Valid(ctx context.Context) bool {
if !c.Rule.Valid(ctx) {
return false
}
return c.next.Valid(ctx)
}
1
https://gitee.com/cuijun/iris_v1111.git
git@gitee.com:cuijun/iris_v1111.git
cuijun
iris_v1111
iris_v1111
1a5f2c173b4a

搜索帮助

53164aa7 5694891 3bd8fe86 5694891