Files
EdgeCommon/pkg/serverconfigs/server_name_config.go

28 lines
920 B
Go
Raw Normal View History

2020-09-13 19:27:47 +08:00
package serverconfigs
2020-09-26 08:07:24 +08:00
import "github.com/TeaOSLab/EdgeCommon/pkg/configutils"
2020-09-13 19:27:47 +08:00
type ServerNameType = string
const (
2020-11-01 18:01:59 +08:00
ServerNameTypeFull ServerNameType = "full" // 完整的域名,包含通配符等
ServerNameTypePrefix ServerNameType = "prefix" // 前缀
ServerNameTypeSuffix ServerNameType = "suffix" // 后缀
ServerNameTypeMatch ServerNameType = "match" // 正则匹配
2020-09-13 19:27:47 +08:00
)
// 主机名(域名)配置
type ServerNameConfig struct {
2020-11-01 18:01:59 +08:00
Name string `yaml:"name" json:"name"` // 名称
Type string `yaml:"type" json:"type"` // 类型
SubNames []string `yaml:"subNames" json:"subNames"` // 子名称,用来支持大量的域名批量管理
2020-09-13 19:27:47 +08:00
}
// 判断主机名是否匹配
func (this *ServerNameConfig) Match(name string) bool {
2020-11-01 18:01:59 +08:00
if len(this.SubNames) > 0 {
return configutils.MatchDomains(this.SubNames, name)
}
2020-09-13 19:27:47 +08:00
return configutils.MatchDomains([]string{this.Name}, name)
}