improve: 修改 ddns 包依赖结构
This commit is contained in:
@@ -2,14 +2,13 @@ package dns
|
||||
|
||||
import (
|
||||
"github.com/Mmx233/BitSrunLoginGo/dns/aliyun"
|
||||
"github.com/Mmx233/BitSrunLoginGo/dns/models"
|
||||
"github.com/mitchellh/mapstructure"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func Run(provider, ip string, conf map[string]interface{}) error {
|
||||
var meta models.BasicConfig
|
||||
e := mapstructure.Decode(conf, &meta)
|
||||
func Run(c *Config) error {
|
||||
var meta BasicConfig
|
||||
e := mapstructure.Decode(c.Conf, &meta)
|
||||
if e != nil {
|
||||
log.Warnf("解析 DDNS 配置失败:%v", e)
|
||||
return e
|
||||
@@ -17,12 +16,12 @@ func Run(provider, ip string, conf map[string]interface{}) error {
|
||||
|
||||
// 配置解析
|
||||
|
||||
var dns models.DnsProvider
|
||||
switch provider {
|
||||
var dns Provider
|
||||
switch c.Provider {
|
||||
case "aliyun":
|
||||
dns, e = aliyun.New(meta.Other)
|
||||
default:
|
||||
log.Warnf("DDNS 模块 dns 运营商 %s 不支持", provider)
|
||||
log.Warnf("DDNS 模块 dns 运营商 %s 不支持", c.Provider)
|
||||
return nil
|
||||
}
|
||||
if e != nil {
|
||||
@@ -32,7 +31,7 @@ func Run(provider, ip string, conf map[string]interface{}) error {
|
||||
|
||||
// 修改 dns 记录
|
||||
|
||||
if e = dns.SetDomainRecord(meta.Domain, ip); e != nil {
|
||||
if e = dns.SetDomainRecord(meta.Domain, c.IP); e != nil {
|
||||
log.Warnf("设置 dns 解析记录失败:%v", e)
|
||||
return e
|
||||
}
|
||||
|
||||
19
dns/models.go
Normal file
19
dns/models.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package dns
|
||||
|
||||
import "net/http"
|
||||
|
||||
type Provider interface {
|
||||
SetDomainRecord(domain, ip string) error
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
Provider string
|
||||
IP string
|
||||
Conf map[string]interface{}
|
||||
Http *http.Client
|
||||
}
|
||||
|
||||
type BasicConfig struct {
|
||||
Domain string `mapstructure:"domain"`
|
||||
Other map[string]interface{} `mapstructure:",remain"`
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
package models
|
||||
|
||||
type BasicConfig struct {
|
||||
Domain string `mapstructure:"domain"`
|
||||
Other map[string]interface{} `mapstructure:",remain"`
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package models
|
||||
|
||||
type DnsProvider interface {
|
||||
SetDomainRecord(domain, ip string) error
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package util
|
||||
package dnsUtil
|
||||
|
||||
import (
|
||||
"github.com/mitchellh/mapstructure"
|
||||
|
||||
Reference in New Issue
Block a user