feat: ddns 功能调用逻辑
This commit is contained in:
14
dns/aliyun/aliyun.go
Normal file
14
dns/aliyun/aliyun.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package aliyun
|
||||
|
||||
import (
|
||||
"github.com/Mmx233/BitSrunLoginGo/dns/models"
|
||||
"github.com/Mmx233/BitSrunLoginGo/dns/util"
|
||||
)
|
||||
|
||||
type DnsProvider struct {
|
||||
}
|
||||
|
||||
func New(conf map[string]interface{}) (models.DnsProvider, error) {
|
||||
var p DnsProvider
|
||||
return &p, util.DecodeConfig(conf, &p)
|
||||
}
|
||||
41
dns/initer.go
Normal file
41
dns/initer.go
Normal file
@@ -0,0 +1,41 @@
|
||||
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)
|
||||
if e != nil {
|
||||
log.Warnf("解析 DDNS 配置失败:%v", e)
|
||||
return e
|
||||
}
|
||||
|
||||
// 配置解析
|
||||
|
||||
var dns models.DnsProvider
|
||||
switch provider {
|
||||
case "aliyun":
|
||||
dns, e = aliyun.New(meta.Other)
|
||||
default:
|
||||
log.Warnf("DDNS 模块 dns 运营商 %s 不支持", provider)
|
||||
return nil
|
||||
}
|
||||
if e != nil {
|
||||
log.Warnf("解析 DDNS 配置失败:%v", e)
|
||||
return e
|
||||
}
|
||||
|
||||
// 修改 dns 记录
|
||||
|
||||
if e = dns.SetDomainRecord(meta.Domain, ip); e != nil {
|
||||
log.Warnf("设置 dns 解析记录失败:%v", e)
|
||||
return e
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
6
dns/models/config.go
Normal file
6
dns/models/config.go
Normal file
@@ -0,0 +1,6 @@
|
||||
package models
|
||||
|
||||
type BasicConfig struct {
|
||||
Domain string `mapstructure:"domain"`
|
||||
Other map[string]interface{} `mapstructure:",remain"`
|
||||
}
|
||||
5
dns/models/interface.go
Normal file
5
dns/models/interface.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package models
|
||||
|
||||
type DnsProvider interface {
|
||||
SetDomainRecord(domain, ip string) error
|
||||
}
|
||||
9
dns/util/config.go
Normal file
9
dns/util/config.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"github.com/mitchellh/mapstructure"
|
||||
)
|
||||
|
||||
func DecodeConfig(conf map[string]interface{}, output interface{}) error {
|
||||
return mapstructure.Decode(conf, output)
|
||||
}
|
||||
Reference in New Issue
Block a user