Files
EdgeCommon/pkg/serverconfigs/shared/http_header_config.go

56 lines
1.1 KiB
Go
Raw Normal View History

2020-09-13 19:27:47 +08:00
package shared
import (
2020-09-26 19:54:20 +08:00
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
2020-09-13 19:27:47 +08:00
)
// 头部信息定义
type HTTPHeaderConfig struct {
2020-09-16 20:29:26 +08:00
Id int64 `yaml:"id" json:"id"` // ID
2020-09-13 19:27:47 +08:00
IsOn bool `yaml:"isOn" json:"isOn"` // 是否开启
Name string `yaml:"name" json:"name"` // Name
Value string `yaml:"value" json:"value"` // Value
Status *HTTPStatusConfig `yaml:"status" json:"status"` // 支持的状态码 TODO
hasVariables bool
}
// 获取新Header对象
func NewHeaderConfig() *HTTPHeaderConfig {
return &HTTPHeaderConfig{
IsOn: true,
}
}
// 校验
func (this *HTTPHeaderConfig) Init() error {
2020-09-26 19:54:20 +08:00
this.hasVariables = configutils.HasVariables(this.Value)
2020-09-13 19:27:47 +08:00
if this.Status != nil {
err := this.Status.Init()
if err != nil {
return err
}
}
return nil
}
// 判断是否匹配状态码
func (this *HTTPHeaderConfig) Match(statusCode int) bool {
if !this.IsOn {
return false
}
if this.Status == nil {
return false
}
return this.Status.Match(statusCode)
}
// 是否有变量
func (this *HTTPHeaderConfig) HasVariables() bool {
return this.hasVariables
}