chore: 修改 DDNS 启动逻辑

This commit is contained in:
Mmx233
2022-12-09 19:23:28 +08:00
parent 388ee21f64
commit 1cc47a39d0
3 changed files with 15 additions and 23 deletions

View File

@@ -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
}