mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 18:51:03 +01:00
0f113dfcda
- Remove the context.Context interface and export the *context, the iris.Context now points to the pointer\nSupport compression and rate limiting in the FileServer\nBit of code organisation Former-commit-id: ad1c61bf968059510c6be9e7f2cceec7da70ba17
56 lines
980 B
Go
56 lines
980 B
Go
package rule
|
|
|
|
import (
|
|
"github.com/kataras/iris/v12/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)
|
|
}
|