From 1cc47a39d0d86d9a5b08f062f8dbe876b597e1d9 Mon Sep 17 00:00:00 2001 From: Mmx233 Date: Fri, 9 Dec 2022 19:23:28 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E4=BF=AE=E6=94=B9=20DDNS=20=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/login.go | 11 +++++++---- dns/initer.go | 19 ++++++------------- dns/models.go | 8 ++------ 3 files changed, 15 insertions(+), 23 deletions(-) diff --git a/controllers/login.go b/controllers/login.go index 712eae9..9d2ca55 100644 --- a/controllers/login.go +++ b/controllers/login.go @@ -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, - })*/ + }) } } diff --git a/dns/initer.go b/dns/initer.go index df2ca8f..b3ff7a5 100644 --- a/dns/initer.go +++ b/dns/initer.go @@ -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 } diff --git a/dns/models.go b/dns/models.go index 2546dc4..885c7f0 100644 --- a/dns/models.go +++ b/dns/models.go @@ -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"` -}