找不到匹配的域名时可以指定默认域名、指定不匹配时的处理动作

This commit is contained in:
GoEdgeLab
2020-11-18 12:17:46 +08:00
parent 937000f1ea
commit b001883c54
3 changed files with 41 additions and 1 deletions

View File

@@ -0,0 +1,25 @@
package serverconfigs
import "github.com/iwind/TeaGo/maps"
const (
DomainMismatchActionPage = "page"
DomainMismatchActionClose = "close"
)
type DomainMismatchPageOptions struct {
StatusCode int `yaml:"statusCode" json:"statusCode"`
ContentHTML string `yaml:"contentHTML" json:"contentHTML"`
}
type DomainMismatchCloseOptions struct {
}
type DomainMismatchAction struct {
Code string `yaml:"code" json:"code"` // 动作代号
Options maps.Map `yaml:"options" json:"options"` // 动作选项
}
func (this *DomainMismatchAction) Init() error {
return nil
}

View File

@@ -4,7 +4,10 @@ package serverconfigs
type GlobalConfig struct {
// HTTP & HTTPS相关配置
HTTPAll struct {
MatchDomainStrictly bool `yaml:"matchDomainStrictly" json:"matchDomainStrictly"` // 是否严格匹配域名
MatchDomainStrictly bool `yaml:"matchDomainStrictly" json:"matchDomainStrictly"` // 是否严格匹配域名
AllowMismatchDomains []string `yaml:"allowMismatchDomains" json:"allowMismatchDomains"` // 允许的不匹配的域名
DefaultDomain string `yaml:"defaultDomain" json:"defaultDomain"` // 默认的域名
DomainMismatchAction *DomainMismatchAction `yaml:"domainMismatchAction" json:"domainMismatchAction"` // 不匹配时采取的动作
} `yaml:"httpAll" json:"httpAll"`
HTTP struct{} `yaml:"http" json:"http"`
@@ -22,5 +25,12 @@ type GlobalConfig struct {
}
func (this *GlobalConfig) Init() error {
// HTTPAll
if this.HTTPAll.DomainMismatchAction != nil {
err := this.HTTPAll.DomainMismatchAction.Init()
if err != nil {
return err
}
}
return nil
}

View File

@@ -195,6 +195,11 @@ func (this *ServerConfig) MatchName(name string) bool {
// 判断是否严格匹配
func (this *ServerConfig) MatchNameStrictly(name string) bool {
for _, serverName := range this.AliasServerNames {
if serverName == name {
return true
}
}
for _, serverName := range this.ServerNames {
if serverName.Name == name {
return true