mirror of
https://github.com/TeaOSLab/EdgeCommon.git
synced 2025-12-30 23:16:37 +08:00
增加字符编码/HTTP Header管理
This commit is contained in:
36
pkg/serverconfigs/http_wildcard_status.go
Normal file
36
pkg/serverconfigs/http_wildcard_status.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package serverconfigs
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// 可能含有x字母的状态码
|
||||
type WildcardStatus struct {
|
||||
StatusInt int
|
||||
StatusRegexp *regexp.Regexp
|
||||
}
|
||||
|
||||
// 获取新对象
|
||||
func NewWildcardStatus(status string) *WildcardStatus {
|
||||
status = regexp.MustCompile("[^0-9x]").ReplaceAllString(status, "")
|
||||
if strings.Contains(status, "x") {
|
||||
return &WildcardStatus{
|
||||
StatusRegexp: regexp.MustCompile("^" + strings.Replace(status, "x", "\\d", -1) + "$"),
|
||||
}
|
||||
} else {
|
||||
return &WildcardStatus{
|
||||
StatusInt: types.Int(status),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 判断匹配
|
||||
func (this *WildcardStatus) Match(status int) bool {
|
||||
if this.StatusRegexp != nil {
|
||||
return this.StatusRegexp.MatchString(fmt.Sprintf("%d", status))
|
||||
}
|
||||
return this.StatusInt == status
|
||||
}
|
||||
Reference in New Issue
Block a user