Explorar o código

修复 HTTPS 配置和加载问题

将 `SSLEmail` 的标签从 `json` 更改为 `yaml`,并在配置加载过程中添加了对 HTTPS 配置的默认设置和检查,同时修正了拼写错误。
SongZihuan hai 2 meses
pai
achega
19598f2596
Modificáronse 3 ficheiros con 8 adicións e 2 borrados
  1. 1 1
      src/config/httpsconfig.go
  2. 6 0
      src/config/yamlconfig.go
  3. 1 1
      src/server/httpsserver/server.go

+ 1 - 1
src/config/httpsconfig.go

@@ -13,7 +13,7 @@ const (
 
 type HttpsConfig struct {
 	Address               string           `yaml:"address"`
-	SSLEmail              string           `json:"ssl-email"`
+	SSLEmail              string           `yaml:"ssl-email"`
 	SSLDomain             string           `yaml:"ssl-domain"`
 	SSLCertDir            string           `yaml:"ssl-cert-dir"`
 	AliyunDNSAccessKey    string           `yaml:"aliyun-dns-access-key"`

+ 6 - 0
src/config/yamlconfig.go

@@ -21,6 +21,7 @@ func (y *YamlConfig) Init() error {
 func (y *YamlConfig) SetDefault() {
 	y.GlobalConfig.SetDefault()
 	y.Http.SetDefault()
+	y.Https.SetDefault()
 	y.RuleListConfig.SetDefault()
 }
 
@@ -35,6 +36,11 @@ func (y *YamlConfig) Check() (err configerr.ConfigError) {
 		return err
 	}
 
+	err = y.Https.Check()
+	if err != nil && err.IsError() {
+		return err
+	}
+
 	err = y.RuleListConfig.Check()
 	if err != nil && err.IsError() {
 		return err

+ 1 - 1
src/server/httpsserver/server.go

@@ -46,7 +46,7 @@ func NewHTTPSServer(handler http.Handler) *HTTPSServer {
 func (s *HTTPSServer) LoadHttps() error {
 	privateKey, certificate, issuerCertificate, err := certssl.GetCertificateAndPrivateKey(s.cfg.SSLCertDir, s.cfg.SSLEmail, s.cfg.AliyunDNSAccessKey, s.cfg.AliyunDNSAccessSecret, s.cfg.SSLDomain)
 	if err != nil {
-		return fmt.Errorf("init htttps cert ssl server error: %s", err.Error())
+		return fmt.Errorf("init https cert ssl server error: %s", err.Error())
 	} else if privateKey == nil || certificate == nil || issuerCertificate == nil {
 		return fmt.Errorf("init https server error: get key and cert error, return nil, unknown reason")
 	}