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