chore: 修改 DDNS 启动逻辑
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"github.com/Mmx233/BitSrunLoginGo/dns"
|
||||
"github.com/Mmx233/BitSrunLoginGo/global"
|
||||
"github.com/Mmx233/BitSrunLoginGo/util"
|
||||
BitSrun "github.com/Mmx233/BitSrunLoginGo/v1"
|
||||
@@ -68,12 +69,14 @@ func Login(localAddr net.Addr, debugOutput bool) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
/*_ = dns.Run(&dns.Config{
|
||||
Provider: providerStr,
|
||||
_ = dns.Run(&dns.Config{
|
||||
Provider: global.Config.Settings.DDNS.Provider,
|
||||
IP: ip,
|
||||
Conf: global.Config.Settings.DDNS,
|
||||
Domain: global.Config.Settings.DDNS.Domain,
|
||||
TTL: global.Config.Settings.DDNS.TTL,
|
||||
Conf: global.Config.Settings.DDNS.Config,
|
||||
Http: httpClient,
|
||||
})*/
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,30 +3,23 @@ package dns
|
||||
import (
|
||||
"github.com/Mmx233/BitSrunLoginGo/dns/aliyun"
|
||||
"github.com/Mmx233/BitSrunLoginGo/dns/cloudflare"
|
||||
"github.com/mitchellh/mapstructure"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func Run(c *Config) error {
|
||||
var meta BasicConfig
|
||||
e := mapstructure.Decode(c.Conf, &meta)
|
||||
if e != nil {
|
||||
log.Warnf("解析 DDNS 配置失败:%v", e)
|
||||
return e
|
||||
}
|
||||
|
||||
if meta.TTL == 0 {
|
||||
meta.TTL = 600
|
||||
if c.TTL == 0 {
|
||||
c.TTL = 600
|
||||
}
|
||||
|
||||
// 配置解析
|
||||
|
||||
var dns Provider
|
||||
var e error
|
||||
switch c.Provider {
|
||||
case "aliyun":
|
||||
dns, e = aliyun.New(meta.TTL, meta.Other, c.Http)
|
||||
dns, e = aliyun.New(c.TTL, c.Conf, c.Http)
|
||||
case "cloudflare":
|
||||
dns, e = cloudflare.New(meta.TTL, meta.Other, c.Http)
|
||||
dns, e = cloudflare.New(c.TTL, c.Conf, c.Http)
|
||||
default:
|
||||
log.Warnf("DDNS 模块 dns 运营商 %s 不支持", c.Provider)
|
||||
return nil
|
||||
@@ -38,7 +31,7 @@ func Run(c *Config) error {
|
||||
|
||||
// 修改 dns 记录
|
||||
|
||||
if e = dns.SetDomainRecord(meta.Domain, c.IP); e != nil {
|
||||
if e = dns.SetDomainRecord(c.Domain, c.IP); e != nil {
|
||||
log.Warnf("设置 dns 解析记录失败:%v", e)
|
||||
return e
|
||||
}
|
||||
|
||||
@@ -9,12 +9,8 @@ type Provider interface {
|
||||
type Config struct {
|
||||
Provider string
|
||||
IP string
|
||||
Domain string
|
||||
TTL uint
|
||||
Conf map[string]interface{}
|
||||
Http *http.Client
|
||||
}
|
||||
|
||||
type BasicConfig struct {
|
||||
Domain string `mapstructure:"domain"`
|
||||
TTL uint `mapstructure:"ttl"`
|
||||
Other map[string]interface{} `mapstructure:",remain"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user