mirror of
https://github.com/TeaOSLab/EdgeCommon.git
synced 2025-11-03 12:20:27 +08:00
38 lines
793 B
Go
38 lines
793 B
Go
package serverconfigs
|
|
|
|
import (
|
|
"fmt"
|
|
"regexp"
|
|
"strings"
|
|
|
|
"github.com/iwind/TeaGo/types"
|
|
)
|
|
|
|
// 可能含有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
|
|
}
|