mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-24 17:28:31 +02:00
fix proxy rules behavior and implemented a few more rules and commands, dependencies upgrade
This commit is contained in:
34
internal/route/rules/check_on.go
Normal file
34
internal/route/rules/check_on.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package rules
|
||||
|
||||
import "net/http"
|
||||
|
||||
type (
|
||||
CheckFunc func(cached Cache, r *http.Request) bool
|
||||
Checker interface {
|
||||
Check(cached Cache, r *http.Request) bool
|
||||
}
|
||||
CheckMatchSingle []Checker
|
||||
CheckMatchAll []Checker
|
||||
)
|
||||
|
||||
func (checker CheckFunc) Check(cached Cache, r *http.Request) bool {
|
||||
return checker(cached, r)
|
||||
}
|
||||
|
||||
func (checkers CheckMatchSingle) Check(cached Cache, r *http.Request) bool {
|
||||
for _, check := range checkers {
|
||||
if check.Check(cached, r) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (checkers CheckMatchAll) Check(cached Cache, r *http.Request) bool {
|
||||
for _, check := range checkers {
|
||||
if !check.Check(cached, r) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
Reference in New Issue
Block a user