From b001883c54f72ddf74b5014e45d558219224f5e1 Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Wed, 18 Nov 2020 12:17:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=BE=E4=B8=8D=E5=88=B0=E5=8C=B9=E9=85=8D?= =?UTF-8?q?=E7=9A=84=E5=9F=9F=E5=90=8D=E6=97=B6=E5=8F=AF=E4=BB=A5=E6=8C=87?= =?UTF-8?q?=E5=AE=9A=E9=BB=98=E8=AE=A4=E5=9F=9F=E5=90=8D=E3=80=81=E6=8C=87?= =?UTF-8?q?=E5=AE=9A=E4=B8=8D=E5=8C=B9=E9=85=8D=E6=97=B6=E7=9A=84=E5=A4=84?= =?UTF-8?q?=E7=90=86=E5=8A=A8=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/serverconfigs/domain_mismatch_action.go | 25 +++++++++++++++++++++ pkg/serverconfigs/global_config.go | 12 +++++++++- pkg/serverconfigs/server_config.go | 5 +++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 pkg/serverconfigs/domain_mismatch_action.go diff --git a/pkg/serverconfigs/domain_mismatch_action.go b/pkg/serverconfigs/domain_mismatch_action.go new file mode 100644 index 0000000..1fe02b4 --- /dev/null +++ b/pkg/serverconfigs/domain_mismatch_action.go @@ -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 +} diff --git a/pkg/serverconfigs/global_config.go b/pkg/serverconfigs/global_config.go index 3470cc4..b53ee4f 100644 --- a/pkg/serverconfigs/global_config.go +++ b/pkg/serverconfigs/global_config.go @@ -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 } diff --git a/pkg/serverconfigs/server_config.go b/pkg/serverconfigs/server_config.go index 18e0a40..491a3eb 100644 --- a/pkg/serverconfigs/server_config.go +++ b/pkg/serverconfigs/server_config.go @@ -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