style: 变量命名
This commit is contained in:
@@ -28,9 +28,9 @@ func New(ttl uint, conf map[string]interface{}, Http *http.Client) (*DnsProvider
|
||||
TTL: ttl,
|
||||
Http: tool.NewHttpTool(Http),
|
||||
}
|
||||
e := dnsUtil.DecodeConfig(conf, &p)
|
||||
if e != nil {
|
||||
return nil, e
|
||||
err := dnsUtil.DecodeConfig(conf, &p)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if p.AccessKeyId == "" || p.AccessKeySecret == "" {
|
||||
@@ -74,9 +74,9 @@ func (a DnsProvider) SendRequest(Type, Action string, data map[string]interface{
|
||||
}
|
||||
|
||||
mac := hmac.New(sha1.New, []byte(a.AccessKeySecret+"&"))
|
||||
_, e := mac.Write([]byte(signStr))
|
||||
if e != nil {
|
||||
return nil, e
|
||||
_, err := mac.Write([]byte(signStr))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
data["Signature"] = base64.StdEncoding.EncodeToString(mac.Sum(nil))
|
||||
|
||||
@@ -86,16 +86,16 @@ func (a DnsProvider) SendRequest(Type, Action string, data map[string]interface{
|
||||
reqOpt.Body = data
|
||||
}
|
||||
|
||||
resp, e := a.Http.Request(Type, &reqOpt)
|
||||
if e != nil {
|
||||
return nil, e
|
||||
resp, err := a.Http.Request(Type, &reqOpt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if resp.StatusCode > 299 {
|
||||
defer resp.Body.Close()
|
||||
var res Response
|
||||
if e = json.NewDecoder(resp.Body).Decode(&res); e != nil {
|
||||
return nil, e
|
||||
if err = json.NewDecoder(resp.Body).Decode(&res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return nil, errors.New(res.Message)
|
||||
@@ -105,21 +105,21 @@ func (a DnsProvider) SendRequest(Type, Action string, data map[string]interface{
|
||||
}
|
||||
|
||||
func (a DnsProvider) DomainRecordStatus(subDomain, rootDomain string) (*DomainStatus, bool, error) {
|
||||
resp, e := a.SendRequest("GET", "DescribeDomainRecords", map[string]interface{}{
|
||||
resp, err := a.SendRequest("GET", "DescribeDomainRecords", map[string]interface{}{
|
||||
"DomainName": rootDomain,
|
||||
"SearchMode": "EXACT",
|
||||
"KeyWord": subDomain,
|
||||
"PageSize": 1,
|
||||
"Type": "A",
|
||||
})
|
||||
if e != nil {
|
||||
return nil, false, e
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
var res DomainStatusRes
|
||||
if e = json.NewDecoder(resp.Body).Decode(&res); e != nil {
|
||||
return nil, false, e
|
||||
if err = json.NewDecoder(resp.Body).Decode(&res); err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
if res.TotalCount == 0 || len(res.DomainRecords.Record) == 0 {
|
||||
@@ -130,15 +130,15 @@ func (a DnsProvider) DomainRecordStatus(subDomain, rootDomain string) (*DomainSt
|
||||
}
|
||||
|
||||
func (a DnsProvider) UpdateRecord(RecordId, subDomain, ip string) error {
|
||||
resp, e := a.SendRequest("POST", "UpdateDomainRecord", map[string]interface{}{
|
||||
resp, err := a.SendRequest("POST", "UpdateDomainRecord", map[string]interface{}{
|
||||
"RecordId": RecordId,
|
||||
"RR": subDomain,
|
||||
"Type": "A",
|
||||
"Value": ip,
|
||||
"TTL": a.TTL,
|
||||
})
|
||||
if e != nil {
|
||||
return e
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
@@ -146,15 +146,15 @@ func (a DnsProvider) UpdateRecord(RecordId, subDomain, ip string) error {
|
||||
}
|
||||
|
||||
func (a DnsProvider) NewRecord(subDomain, rootDomain, ip string) error {
|
||||
resp, e := a.SendRequest("POST", "AddDomainRecord", map[string]interface{}{
|
||||
resp, err := a.SendRequest("POST", "AddDomainRecord", map[string]interface{}{
|
||||
"DomainName": rootDomain,
|
||||
"RR": subDomain,
|
||||
"Type": "A",
|
||||
"Value": ip,
|
||||
"TTL": a.TTL,
|
||||
})
|
||||
if e != nil {
|
||||
return e
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
@@ -162,14 +162,14 @@ func (a DnsProvider) NewRecord(subDomain, rootDomain, ip string) error {
|
||||
}
|
||||
|
||||
func (a DnsProvider) SetDomainRecord(domain, ip string) error {
|
||||
subDomain, rootDomain, e := dnsUtil.DecodeDomain(domain)
|
||||
if e != nil {
|
||||
return e
|
||||
subDomain, rootDomain, err := dnsUtil.DecodeDomain(domain)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
record, exist, e := a.DomainRecordStatus(subDomain, rootDomain)
|
||||
if e != nil {
|
||||
return e
|
||||
record, exist, err := a.DomainRecordStatus(subDomain, rootDomain)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if exist {
|
||||
|
||||
@@ -20,9 +20,9 @@ func New(ttl int, conf map[string]interface{}, Http *http.Client) (*DnsProvider,
|
||||
var p = DnsProvider{
|
||||
TTL: ttl,
|
||||
}
|
||||
e := dnsUtil.DecodeConfig(conf, &p)
|
||||
if e != nil {
|
||||
return nil, e
|
||||
err := dnsUtil.DecodeConfig(conf, &p)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if p.Zone == "" {
|
||||
@@ -34,36 +34,36 @@ func New(ttl int, conf map[string]interface{}, Http *http.Client) (*DnsProvider,
|
||||
return nil, errors.New("cloudflare token 不能为空")
|
||||
}
|
||||
|
||||
p.Api, e = cloudflare.NewWithAPIToken(p.Token, cloudflare.HTTPClient(Http))
|
||||
return &p, e
|
||||
p.Api, err = cloudflare.NewWithAPIToken(p.Token, cloudflare.HTTPClient(Http))
|
||||
return &p, err
|
||||
}
|
||||
|
||||
func (a DnsProvider) SetDomainRecord(domain, ip string) error {
|
||||
records, _, e := a.Api.ListDNSRecords(context.Background(), a.ZoneResource, cloudflare.ListDNSRecordsParams{
|
||||
records, _, err := a.Api.ListDNSRecords(context.Background(), a.ZoneResource, cloudflare.ListDNSRecordsParams{
|
||||
Type: "A",
|
||||
Name: domain,
|
||||
})
|
||||
if e != nil {
|
||||
return e
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(records) == 0 {
|
||||
_, e = a.Api.CreateDNSRecord(context.Background(), a.ZoneResource, cloudflare.CreateDNSRecordParams{
|
||||
_, err = a.Api.CreateDNSRecord(context.Background(), a.ZoneResource, cloudflare.CreateDNSRecordParams{
|
||||
Type: "A",
|
||||
Name: domain,
|
||||
Content: ip,
|
||||
TTL: a.TTL,
|
||||
})
|
||||
return e
|
||||
return err
|
||||
} else {
|
||||
record := records[0]
|
||||
if record.Content == ip {
|
||||
return nil
|
||||
}
|
||||
_, e = a.Api.UpdateDNSRecord(context.Background(), a.ZoneResource, cloudflare.UpdateDNSRecordParams{
|
||||
_, err = a.Api.UpdateDNSRecord(context.Background(), a.ZoneResource, cloudflare.UpdateDNSRecordParams{
|
||||
ID: record.ID,
|
||||
Content: ip,
|
||||
})
|
||||
return e
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package dnspod
|
||||
|
||||
import (
|
||||
dnsUtil2 "github.com/Mmx233/BitSrunLoginGo/internal/pkg/dns/util"
|
||||
dnsUtil "github.com/Mmx233/BitSrunLoginGo/internal/pkg/dns/util"
|
||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
|
||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
|
||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/regions"
|
||||
@@ -19,19 +19,19 @@ type DnsProvider struct {
|
||||
|
||||
func New(ttl uint64, conf map[string]interface{}, Http http.RoundTripper) (*DnsProvider, error) {
|
||||
var p = DnsProvider{TTL: ttl}
|
||||
e := dnsUtil2.DecodeConfig(conf, &p)
|
||||
if e != nil {
|
||||
return nil, e
|
||||
err := dnsUtil.DecodeConfig(conf, &p)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p.Client, e = dnspod.NewClient(common.NewCredential(p.SecretId, p.SecretKey), regions.Guangzhou, profile.NewClientProfile())
|
||||
p.Client, err = dnspod.NewClient(common.NewCredential(p.SecretId, p.SecretKey), regions.Guangzhou, profile.NewClientProfile())
|
||||
p.Client.WithHttpTransport(Http)
|
||||
return &p, e
|
||||
return &p, err
|
||||
}
|
||||
|
||||
func (a DnsProvider) SetDomainRecord(domain, ip string) error {
|
||||
subDomain, rootDomain, e := dnsUtil2.DecodeDomain(domain)
|
||||
if e != nil {
|
||||
return e
|
||||
subDomain, rootDomain, err := dnsUtil.DecodeDomain(domain)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -44,8 +44,8 @@ func (a DnsProvider) SetDomainRecord(domain, ip string) error {
|
||||
reqRecordList.Domain = &rootDomain
|
||||
reqRecordList.Subdomain = &subDomain
|
||||
reqRecordList.Limit = &limit
|
||||
res, e := a.Client.DescribeRecordList(reqRecordList)
|
||||
if (e != nil && strings.Contains(e.Error(), dnspod.RESOURCENOTFOUND_NODATAOFRECORD)) || (e == nil && len(res.Response.RecordList) == 0) {
|
||||
res, err := a.Client.DescribeRecordList(reqRecordList)
|
||||
if (err != nil && strings.Contains(err.Error(), dnspod.RESOURCENOTFOUND_NODATAOFRECORD)) || (err == nil && len(res.Response.RecordList) == 0) {
|
||||
reqNewRecord := dnspod.NewCreateRecordRequest()
|
||||
reqNewRecord.TTL = &a.TTL
|
||||
reqNewRecord.Domain = &rootDomain
|
||||
@@ -53,10 +53,10 @@ func (a DnsProvider) SetDomainRecord(domain, ip string) error {
|
||||
reqNewRecord.RecordLine = &recordLine
|
||||
reqNewRecord.Value = &ip
|
||||
reqNewRecord.SubDomain = &subDomain
|
||||
_, e = a.Client.CreateRecord(reqNewRecord)
|
||||
return e
|
||||
} else if e != nil {
|
||||
return e
|
||||
_, err = a.Client.CreateRecord(reqNewRecord)
|
||||
return err
|
||||
} else if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
reqModifyRecord := dnspod.NewModifyRecordRequest()
|
||||
@@ -66,6 +66,6 @@ func (a DnsProvider) SetDomainRecord(domain, ip string) error {
|
||||
reqModifyRecord.RecordId = res.Response.RecordList[0].RecordId
|
||||
reqModifyRecord.RecordLine = &recordLine
|
||||
reqModifyRecord.RecordType = &recordType
|
||||
_, e = a.Client.ModifyRecord(reqModifyRecord)
|
||||
return e
|
||||
_, err = a.Client.ModifyRecord(reqModifyRecord)
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user