-
Notifications
You must be signed in to change notification settings - Fork 34
/
page.go
42 lines (37 loc) · 970 Bytes
/
page.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package teaconfigs
// 特殊页面配置
type PageConfig struct {
On bool `yaml:"on" json:"on"` // TODO
Status []string `yaml:"status" json:"status"` // 响应支持40x, 50x, 3x2
URL string `yaml:"url" json:"url"` // URL
NewStatus int `yaml:"newStatus" json:"newStatus"` // 新状态码
statusList []*WildcardStatus
hasStatusList bool
}
// 获取新对象
func NewPageConfig() *PageConfig {
return &PageConfig{
On: true,
}
}
// 校验
func (this *PageConfig) Validate() error {
this.statusList = []*WildcardStatus{}
for _, s := range this.Status {
this.statusList = append(this.statusList, NewWildcardStatus(s))
}
this.hasStatusList = len(this.statusList) > 0
return nil
}
// 检查是否匹配
func (this *PageConfig) Match(status int) bool {
if !this.hasStatusList {
return false
}
for _, s := range this.statusList {
if s.Match(status) {
return true
}
}
return false
}