mirror of
https://github.com/TeaOSLab/EdgeCommon.git
synced 2026-04-21 12:15:19 +08:00
修复请求条件可能会重复调用的问题
This commit is contained in:
@@ -16,7 +16,7 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// 重写条件定义
|
||||
// HTTPRequestCond HTTP请求匹配条件定义
|
||||
type HTTPRequestCond struct {
|
||||
Type string `yaml:"type" json:"type"` // 类型,在特殊条件时使用
|
||||
IsRequest bool `yaml:"isRequest" json:"isRequest"` // 是否为请求的条件,用来区分在什么阶段执行
|
||||
@@ -39,7 +39,7 @@ type HTTPRequestCond struct {
|
||||
arrayValue []string
|
||||
}
|
||||
|
||||
// 校验配置
|
||||
// Init 校验配置
|
||||
func (this *HTTPRequestCond) Init() error {
|
||||
this.isInt = RegexpDigitNumber.MatchString(this.Value)
|
||||
this.isFloat = RegexpFloatNumber.MatchString(this.Value)
|
||||
@@ -134,7 +134,7 @@ func (this *HTTPRequestCond) Init() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// 将此条件应用于请求,检查是否匹配
|
||||
// Match 将此条件应用于请求,检查是否匹配
|
||||
func (this *HTTPRequestCond) Match(formatter func(source string) string) bool {
|
||||
paramValue := formatter(this.Param)
|
||||
switch this.Operator {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package shared
|
||||
|
||||
// 请求条件分组
|
||||
// HTTPRequestCondGroup 请求条件分组
|
||||
type HTTPRequestCondGroup struct {
|
||||
IsOn bool `yaml:"isOn" json:"isOn"` // 是否启用
|
||||
Connector string `yaml:"connector" json:"connector"` // 条件之间的关系
|
||||
@@ -12,12 +12,14 @@ type HTTPRequestCondGroup struct {
|
||||
responseConds []*HTTPRequestCond
|
||||
}
|
||||
|
||||
// 初始化
|
||||
// Init 初始化
|
||||
func (this *HTTPRequestCondGroup) Init() error {
|
||||
if len(this.Connector) == 0 {
|
||||
this.Connector = "or"
|
||||
}
|
||||
|
||||
this.requestConds = []*HTTPRequestCond{}
|
||||
this.responseConds = []*HTTPRequestCond{}
|
||||
if len(this.Conds) > 0 {
|
||||
for _, cond := range this.Conds {
|
||||
err := cond.Init()
|
||||
|
||||
Reference in New Issue
Block a user