mirror of
https://github.com/TeaOSLab/EdgeCommon.git
synced 2026-01-06 20:15:50 +08:00
实现HTTP部分功能
This commit is contained in:
38
pkg/serverconfigs/shared/http_request_cond_group.go
Normal file
38
pkg/serverconfigs/shared/http_request_cond_group.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package shared
|
||||
|
||||
// 请求条件分组
|
||||
type HTTPRequestCondGroup struct {
|
||||
IsOn bool `yaml:"isOn" json:"isOn"` // 是否启用
|
||||
Connector string `yaml:"connector" json:"connector"` // 条件之间的关系
|
||||
Conds []*HTTPRequestCond `yaml:"conds" json:"conds"` // 条件列表
|
||||
IsReverse bool `yaml:"isReverse" json:"isReverse"` // 是否反向匹配
|
||||
}
|
||||
|
||||
// 初始化
|
||||
func (this *HTTPRequestCondGroup) Init() error {
|
||||
if len(this.Conds) > 0 {
|
||||
for _, cond := range this.Conds {
|
||||
err := cond.Init()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this *HTTPRequestCondGroup) Match(formatter func(source string) string) bool {
|
||||
if !this.IsOn {
|
||||
return !this.IsReverse
|
||||
}
|
||||
for _, cond := range this.Conds {
|
||||
isMatched := cond.Match(formatter)
|
||||
if this.Connector == "or" && isMatched {
|
||||
return !this.IsReverse
|
||||
}
|
||||
if this.Connector == "and" && !isMatched {
|
||||
return this.IsReverse
|
||||
}
|
||||
}
|
||||
return !this.IsReverse
|
||||
}
|
||||
Reference in New Issue
Block a user