improve: 优化 DDNS 配置读取形式

This commit is contained in:
Mmx233
2022-12-09 19:20:32 +08:00
parent 33283c66c9
commit 388ee21f64
3 changed files with 30 additions and 30 deletions

View File

@@ -1,7 +1,6 @@
package controllers
import (
"github.com/Mmx233/BitSrunLoginGo/dns"
"github.com/Mmx233/BitSrunLoginGo/global"
"github.com/Mmx233/BitSrunLoginGo/util"
BitSrun "github.com/Mmx233/BitSrunLoginGo/v1"
@@ -59,29 +58,23 @@ func Login(localAddr net.Addr, debugOutput bool) error {
}
log.Infoln("登录成功~")
}
// DDNS
// DDNS
if global.Config.Settings.DDNS.Enable {
log.Debugln("开始 DDNS 设置流程")
enable, _ := global.Config.Settings.DDNS["enable"]
if open, _ := enable.(bool); open {
log.Debugln("开始 DDNS 设置流程")
if global.Config.Settings.DDNS.Provider == "" {
log.Warnln("DDNS 模块 dns 运营商不能为空")
return nil
}
provider, _ := global.Config.Settings.DDNS["provider"]
providerStr, _ := provider.(string)
if providerStr == "" {
log.Warnln("DDNS 模块 dns 运营商不能为空")
return nil
/*_ = dns.Run(&dns.Config{
Provider: providerStr,
IP: ip,
Conf: global.Config.Settings.DDNS,
Http: httpClient,
})*/
}
delete(global.Config.Settings.DDNS, "provider")
_ = dns.Run(&dns.Config{
Provider: providerStr,
IP: ip,
Conf: global.Config.Settings.DDNS,
Http: httpClient,
})
}
return nil

View File

@@ -39,11 +39,10 @@ func readConfig() {
Log: srunModels.Log{
FilePath: "./",
},
DDNS: map[string]interface{}{
"enable": false,
"domain": "www.example.com",
"ttl": 600,
"provider": "",
DDNS: srunModels.DDNS{
Enable: false,
TTL: 600,
Domain: "www.example.com",
},
})

View File

@@ -29,12 +29,20 @@ type Log struct {
FileName string `json:"log_name" yaml:"log_name" mapstructure:"log_name"`
}
type DDNS struct {
Enable bool `json:"enable" yaml:"enable" mapstructure:"enable"`
TTL uint `json:"ttl" yaml:"ttl" mapstructure:"ttl"`
Domain string `json:"domain" yaml:"domain" mapstructure:"domain"`
Provider string `json:"provider" yaml:"provider" mapstructure:"provider"`
Config map[string]interface{} `mapstructure:",remain"`
}
type Settings struct {
Basic Basic `json:"basic" yaml:"basic" mapstructure:"basic"`
Guardian Guardian `json:"guardian" yaml:"guardian" mapstructure:"guardian"`
Daemon Daemon `json:"daemon" yaml:"daemon" mapstructure:"daemon"`
Log Log `json:"log" yaml:"log" mapstructure:"log"`
DDNS map[string]interface{} `json:"ddns" yaml:"ddns" mapstructure:"ddns"`
Basic Basic `json:"basic" yaml:"basic" mapstructure:"basic"`
Guardian Guardian `json:"guardian" yaml:"guardian" mapstructure:"guardian"`
Daemon Daemon `json:"daemon" yaml:"daemon" mapstructure:"daemon"`
Log Log `json:"log" yaml:"log" mapstructure:"log"`
DDNS DDNS `json:"ddns" yaml:"ddns" mapstructure:"ddns"`
}
type Config struct {