build: remove dependency of mapstructre
This commit is contained in:
@@ -16,28 +16,26 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type DnsProvider struct {
|
||||
TTL uint `mapstructure:"-"`
|
||||
Http *tool.Http `mapstructure:"-"`
|
||||
AccessKeyId string `mapstructure:"access_key_id"`
|
||||
AccessKeySecret string `mapstructure:"access_key_secret"`
|
||||
type Aliyun struct {
|
||||
AccessKeyId string `json:"access_key_id,omitempty" yaml:"access_key_id,omitempty"`
|
||||
AccessKeySecret string `json:"access_key_secret,omitempty" yaml:"access_key_secret,omitempty"`
|
||||
}
|
||||
|
||||
func New(ttl uint, conf map[string]interface{}, Http *http.Client) (*DnsProvider, error) {
|
||||
var p = DnsProvider{
|
||||
TTL: ttl,
|
||||
Http: tool.NewHttpTool(Http),
|
||||
}
|
||||
err := dnsUtil.DecodeConfig(conf, &p)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
type DnsProvider struct {
|
||||
TTL uint
|
||||
Http *tool.Http
|
||||
Aliyun
|
||||
}
|
||||
|
||||
if p.AccessKeyId == "" || p.AccessKeySecret == "" {
|
||||
func New(ttl uint, conf Aliyun, Http *http.Client) (*DnsProvider, error) {
|
||||
if conf.AccessKeyId == "" || conf.AccessKeySecret == "" {
|
||||
return nil, errors.New("aliyun AccessKey 不能为空")
|
||||
}
|
||||
|
||||
return &p, nil
|
||||
return &DnsProvider{
|
||||
TTL: ttl,
|
||||
Http: tool.NewHttpTool(Http),
|
||||
Aliyun: conf,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (a DnsProvider) SendRequest(Type, Action string, data map[string]interface{}) (*http.Response, error) {
|
||||
|
||||
@@ -3,37 +3,35 @@ package cloudflare
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/Mmx233/BitSrunLoginGo/internal/pkg/dns/util"
|
||||
"github.com/cloudflare/cloudflare-go"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type DnsProvider struct {
|
||||
Api *cloudflare.API `mapstructure:"-"`
|
||||
TTL int `mapstructure:"-"`
|
||||
Zone string `mapstructure:"zone"`
|
||||
ZoneResource *cloudflare.ResourceContainer `mapstructure:"-"`
|
||||
Token string `mapstructure:"token"`
|
||||
type Cloudflare struct {
|
||||
Zone string `json:"zone" yaml:"zone"`
|
||||
Token string `json:"token" yaml:"token"`
|
||||
}
|
||||
|
||||
func New(ttl int, conf map[string]interface{}, Http *http.Client) (*DnsProvider, error) {
|
||||
var p = DnsProvider{
|
||||
TTL: ttl,
|
||||
}
|
||||
err := dnsUtil.DecodeConfig(conf, &p)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
type DnsProvider struct {
|
||||
Api *cloudflare.API
|
||||
TTL int
|
||||
ZoneResource *cloudflare.ResourceContainer
|
||||
Cloudflare
|
||||
}
|
||||
|
||||
func New(ttl int, conf Cloudflare, Http *http.Client) (*DnsProvider, error) {
|
||||
var p = DnsProvider{
|
||||
TTL: ttl,
|
||||
Cloudflare: conf,
|
||||
}
|
||||
if p.Zone == "" {
|
||||
return nil, errors.New("cloudflare zone 不能为空")
|
||||
}
|
||||
p.ZoneResource = cloudflare.ZoneIdentifier(p.Zone)
|
||||
|
||||
if p.Token == "" {
|
||||
return nil, errors.New("cloudflare token 不能为空")
|
||||
}
|
||||
|
||||
p.ZoneResource = cloudflare.ZoneIdentifier(p.Zone)
|
||||
var err error
|
||||
p.Api, err = cloudflare.NewWithAPIToken(p.Token, cloudflare.HTTPClient(Http))
|
||||
return &p, err
|
||||
}
|
||||
|
||||
@@ -16,17 +16,15 @@ func Run(c *Config) error {
|
||||
c.TTL = 600
|
||||
}
|
||||
|
||||
// 配置解析
|
||||
|
||||
var dns Provider
|
||||
var err error
|
||||
switch c.Provider {
|
||||
case "aliyun":
|
||||
dns, err = aliyun.New(c.TTL, c.Conf, c.Http)
|
||||
dns, err = aliyun.New(c.TTL, c.Conf.Aliyun, c.Http)
|
||||
case "cloudflare":
|
||||
dns, err = cloudflare.New(int(c.TTL), c.Conf, c.Http)
|
||||
dns, err = cloudflare.New(int(c.TTL), c.Conf.Cloudflare, c.Http)
|
||||
case "dnspod":
|
||||
dns, err = dnspod.New(uint64(c.TTL), c.Conf, c.Http.Transport)
|
||||
dns, err = dnspod.New(uint64(c.TTL), c.Conf.DnsPod, c.Http.Transport)
|
||||
default:
|
||||
var msg string
|
||||
if c.Provider == "" {
|
||||
|
||||
@@ -10,19 +10,20 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
type DnsProvider struct {
|
||||
Client *dnspod.Client `mapstructure:"-"`
|
||||
TTL uint64 `mapstructure:"-"`
|
||||
SecretId string `mapstructure:"secret_id"`
|
||||
SecretKey string `mapstructure:"secret_key"`
|
||||
type DnsPod struct {
|
||||
SecretId string `json:"secret_id,omitempty" yaml:"secret_id,omitempty"`
|
||||
SecretKey string `json:"secret_key,omitempty" yaml:"secret_key,omitempty"`
|
||||
}
|
||||
|
||||
func New(ttl uint64, conf map[string]interface{}, Http http.RoundTripper) (*DnsProvider, error) {
|
||||
var p = DnsProvider{TTL: ttl}
|
||||
err := dnsUtil.DecodeConfig(conf, &p)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
type DnsProvider struct {
|
||||
Client *dnspod.Client
|
||||
TTL uint64
|
||||
DnsPod
|
||||
}
|
||||
|
||||
func New(ttl uint64, conf DnsPod, Http http.RoundTripper) (*DnsProvider, error) {
|
||||
var p = DnsProvider{TTL: ttl, DnsPod: conf}
|
||||
var err error
|
||||
p.Client, err = dnspod.NewClient(common.NewCredential(p.SecretId, p.SecretKey), regions.Guangzhou, profile.NewClientProfile())
|
||||
p.Client.WithHttpTransport(Http)
|
||||
return &p, err
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package dns
|
||||
|
||||
import "net/http"
|
||||
import (
|
||||
"github.com/Mmx233/BitSrunLoginGo/internal/config"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type Provider interface {
|
||||
SetDomainRecord(domain, ip string) error
|
||||
@@ -11,6 +14,6 @@ type Config struct {
|
||||
IP string
|
||||
Domain string
|
||||
TTL uint
|
||||
Conf map[string]interface{}
|
||||
Conf config.DdnsProviderConfigSum
|
||||
Http *http.Client
|
||||
}
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
package dnsUtil
|
||||
|
||||
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