mirror of
https://github.com/jeessy2/ddns-go.git
synced 2025-10-20 15:33:46 +08:00
fix: display the error logs first (#973)
This commit is contained in:
@ -119,11 +119,17 @@ func (ali *Alidns) create(domain *config.Domain, recordType string, ipAddr strin
|
||||
var result AlidnsResp
|
||||
err := ali.request(params, &result)
|
||||
|
||||
if err == nil && result.RecordID != "" {
|
||||
if err != nil {
|
||||
util.Log("新增域名解析 %s 失败! 异常信息: %s", domain, err)
|
||||
domain.UpdateStatus = config.UpdatedFailed
|
||||
return
|
||||
}
|
||||
|
||||
if result.RecordID != "" {
|
||||
util.Log("新增域名解析 %s 成功! IP: %s", domain, ipAddr)
|
||||
domain.UpdateStatus = config.UpdatedSuccess
|
||||
} else {
|
||||
util.Log("新增域名解析 %s 失败! 异常信息: %s", domain, err)
|
||||
util.Log("新增域名解析 %s 失败! 异常信息: %s", domain, "返回RecordId为空")
|
||||
domain.UpdateStatus = config.UpdatedFailed
|
||||
}
|
||||
}
|
||||
@ -148,11 +154,17 @@ func (ali *Alidns) modify(recordSelected AlidnsRecord, domain *config.Domain, re
|
||||
var result AlidnsResp
|
||||
err := ali.request(params, &result)
|
||||
|
||||
if err == nil && result.RecordID != "" {
|
||||
if err != nil {
|
||||
util.Log("更新域名解析 %s 失败! 异常信息: %s", domain, err)
|
||||
domain.UpdateStatus = config.UpdatedFailed
|
||||
return
|
||||
}
|
||||
|
||||
if result.RecordID != "" {
|
||||
util.Log("更新域名解析 %s 成功! IP: %s", domain, ipAddr)
|
||||
domain.UpdateStatus = config.UpdatedSuccess
|
||||
} else {
|
||||
util.Log("更新域名解析 %s 失败! 异常信息: %s", domain, err)
|
||||
util.Log("更新域名解析 %s 失败! 异常信息: %s", domain, "返回RecordId为空")
|
||||
domain.UpdateStatus = config.UpdatedFailed
|
||||
}
|
||||
}
|
||||
@ -170,7 +182,6 @@ func (ali *Alidns) request(params url.Values, result interface{}) (err error) {
|
||||
req.URL.RawQuery = params.Encode()
|
||||
|
||||
if err != nil {
|
||||
util.Log("异常信息: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -193,7 +193,6 @@ func (baidu *BaiduCloud) request(method string, url string, data interface{}, re
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
util.Log("异常信息: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -82,6 +82,7 @@ func (cb *Callback) addUpdateDomainRecords(recordType string) {
|
||||
req, err := http.NewRequest(method, u.String(), strings.NewReader(postPara))
|
||||
if err != nil {
|
||||
util.Log("异常信息: %s", err)
|
||||
domain.UpdateStatus = config.UpdatedFailed
|
||||
return
|
||||
}
|
||||
req.Header.Add("content-type", contentType)
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/jeessy2/ddns-go/v6/config"
|
||||
"github.com/jeessy2/ddns-go/v6/util"
|
||||
@ -91,11 +92,19 @@ func (cf *Cloudflare) addUpdateDomainRecords(recordType string) {
|
||||
for _, domain := range domains {
|
||||
// get zone
|
||||
result, err := cf.getZones(domain)
|
||||
if err != nil || len(result.Result) != 1 {
|
||||
|
||||
if err != nil {
|
||||
util.Log("查询域名信息发生异常! %s", err)
|
||||
domain.UpdateStatus = config.UpdatedFailed
|
||||
return
|
||||
}
|
||||
|
||||
if len(result.Result) == 0 {
|
||||
util.Log("在DNS服务商中未找到域名: %s", domain.String())
|
||||
domain.UpdateStatus = config.UpdatedFailed
|
||||
return
|
||||
}
|
||||
|
||||
zoneID := result.Result[0].ID
|
||||
|
||||
var records CloudflareRecordsResp
|
||||
@ -107,8 +116,15 @@ func (cf *Cloudflare) addUpdateDomainRecords(recordType string) {
|
||||
&records,
|
||||
)
|
||||
|
||||
if err != nil || !records.Success {
|
||||
if err != nil {
|
||||
util.Log("查询域名信息发生异常! %s", err)
|
||||
domain.UpdateStatus = config.UpdatedFailed
|
||||
return
|
||||
}
|
||||
|
||||
if !records.Success {
|
||||
util.Log("查询域名信息发生异常! %s", strings.Join(records.Messages, ", "))
|
||||
domain.UpdateStatus = config.UpdatedFailed
|
||||
return
|
||||
}
|
||||
|
||||
@ -139,11 +155,18 @@ func (cf *Cloudflare) create(zoneID string, domain *config.Domain, recordType st
|
||||
record,
|
||||
&status,
|
||||
)
|
||||
if err == nil && status.Success {
|
||||
|
||||
if err != nil {
|
||||
util.Log("新增域名解析 %s 失败! 异常信息: %s", domain, err)
|
||||
domain.UpdateStatus = config.UpdatedFailed
|
||||
return
|
||||
}
|
||||
|
||||
if status.Success {
|
||||
util.Log("新增域名解析 %s 成功! IP: %s", domain, ipAddr)
|
||||
domain.UpdateStatus = config.UpdatedSuccess
|
||||
} else {
|
||||
util.Log("新增域名解析 %s 失败! 异常信息: %s", domain, err)
|
||||
util.Log("新增域名解析 %s 失败! 异常信息: %s", domain, strings.Join(status.Messages, ", "))
|
||||
domain.UpdateStatus = config.UpdatedFailed
|
||||
}
|
||||
}
|
||||
@ -169,11 +192,18 @@ func (cf *Cloudflare) modify(result CloudflareRecordsResp, zoneID string, domain
|
||||
record,
|
||||
&status,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
util.Log("更新域名解析 %s 失败! 异常信息: %s", domain, err)
|
||||
domain.UpdateStatus = config.UpdatedFailed
|
||||
return
|
||||
}
|
||||
|
||||
if err == nil && status.Success {
|
||||
util.Log("更新域名解析 %s 成功! IP: %s", domain, ipAddr)
|
||||
domain.UpdateStatus = config.UpdatedSuccess
|
||||
} else {
|
||||
util.Log("更新域名解析 %s 失败! 异常信息: %s", domain, err)
|
||||
util.Log("更新域名解析 %s 失败! 异常信息: %s", domain, strings.Join(status.Messages, ", "))
|
||||
domain.UpdateStatus = config.UpdatedFailed
|
||||
}
|
||||
}
|
||||
@ -203,7 +233,6 @@ func (cf *Cloudflare) request(method string, url string, data interface{}, resul
|
||||
bytes.NewBuffer(jsonStr),
|
||||
)
|
||||
if err != nil {
|
||||
util.Log("异常信息: %s", err)
|
||||
return
|
||||
}
|
||||
req.Header.Set("Authorization", "Bearer "+cf.DNS.Secret)
|
||||
|
@ -116,6 +116,13 @@ func (dnspod *Dnspod) create(domain *config.Domain, recordType string, ipAddr st
|
||||
}
|
||||
|
||||
status, err := dnspod.commonRequest(recordCreateAPI, params, domain)
|
||||
|
||||
if err != nil {
|
||||
util.Log("新增域名解析 %s 失败! 异常信息: %s", domain, err)
|
||||
domain.UpdateStatus = config.UpdatedFailed
|
||||
return
|
||||
}
|
||||
|
||||
if err == nil && status.Status.Code == "1" {
|
||||
util.Log("新增域名解析 %s 成功! IP: %s", domain, ipAddr)
|
||||
domain.UpdateStatus = config.UpdatedSuccess
|
||||
@ -147,8 +154,16 @@ func (dnspod *Dnspod) modify(record DnspodRecord, domain *config.Domain, recordT
|
||||
if !params.Has("record_line") {
|
||||
params.Set("record_line", "默认")
|
||||
}
|
||||
|
||||
status, err := dnspod.commonRequest(recordModifyURL, params, domain)
|
||||
if err == nil && status.Status.Code == "1" {
|
||||
|
||||
if err != nil {
|
||||
util.Log("更新域名解析 %s 失败! 异常信息: %s", domain, err)
|
||||
domain.UpdateStatus = config.UpdatedFailed
|
||||
return
|
||||
}
|
||||
|
||||
if status.Status.Code == "1" {
|
||||
util.Log("更新域名解析 %s 成功! IP: %s", domain, ipAddr)
|
||||
domain.UpdateStatus = config.UpdatedSuccess
|
||||
} else {
|
||||
|
@ -91,7 +91,7 @@ func (gd *GoogleDomain) modify(domain *config.Domain, recordType string, ipAddr
|
||||
util.Log("更新域名解析 %s 成功! IP: %s", domain, ipAddr)
|
||||
domain.UpdateStatus = config.UpdatedSuccess
|
||||
default:
|
||||
util.Log("更新域名解析 %s 失败! 异常信息: %s", domain, result)
|
||||
util.Log("更新域名解析 %s 失败! 异常信息: %s", domain, result.Status)
|
||||
domain.UpdateStatus = config.UpdatedFailed
|
||||
}
|
||||
}
|
||||
@ -106,7 +106,6 @@ func (gd *GoogleDomain) request(params url.Values, result *GoogleDomainResp) (er
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
util.Log("异常信息: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -116,7 +115,6 @@ func (gd *GoogleDomain) request(params url.Values, result *GoogleDomainResp) (er
|
||||
client := util.CreateHTTPClient()
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
util.Log("异常信息: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -121,10 +121,14 @@ func (hw *Huaweicloud) addUpdateDomainRecords(recordType string) {
|
||||
func (hw *Huaweicloud) create(domain *config.Domain, recordType string, ipAddr string) {
|
||||
zone, err := hw.getZones(domain)
|
||||
if err != nil {
|
||||
util.Log("查询域名信息发生异常! %s", err)
|
||||
domain.UpdateStatus = config.UpdatedFailed
|
||||
return
|
||||
}
|
||||
|
||||
if len(zone.Zones) == 0 {
|
||||
util.Log("在DNS服务商中未找到域名: %s", domain.String())
|
||||
domain.UpdateStatus = config.UpdatedFailed
|
||||
return
|
||||
}
|
||||
|
||||
@ -149,11 +153,18 @@ func (hw *Huaweicloud) create(domain *config.Domain, recordType string, ipAddr s
|
||||
record,
|
||||
&result,
|
||||
)
|
||||
if err == nil && (len(result.Records) > 0 && result.Records[0] == ipAddr) {
|
||||
|
||||
if err != nil {
|
||||
util.Log("新增域名解析 %s 失败! 异常信息: %s", domain, err)
|
||||
domain.UpdateStatus = config.UpdatedFailed
|
||||
return
|
||||
}
|
||||
|
||||
if len(result.Records) > 0 && result.Records[0] == ipAddr {
|
||||
util.Log("新增域名解析 %s 成功! IP: %s", domain, ipAddr)
|
||||
domain.UpdateStatus = config.UpdatedSuccess
|
||||
} else {
|
||||
util.Log("新增域名解析 %s 失败! 异常信息: %s", domain, err)
|
||||
util.Log("新增域名解析 %s 失败! 异常信息: %s", domain, result.Status)
|
||||
domain.UpdateStatus = config.UpdatedFailed
|
||||
}
|
||||
}
|
||||
@ -180,11 +191,17 @@ func (hw *Huaweicloud) modify(record HuaweicloudRecordsets, domain *config.Domai
|
||||
&result,
|
||||
)
|
||||
|
||||
if err == nil && (len(result.Records) > 0 && result.Records[0] == ipAddr) {
|
||||
if err != nil {
|
||||
util.Log("更新域名解析 %s 失败! 异常信息: %s", domain, err)
|
||||
domain.UpdateStatus = config.UpdatedFailed
|
||||
return
|
||||
}
|
||||
|
||||
if len(result.Records) > 0 && result.Records[0] == ipAddr {
|
||||
util.Log("更新域名解析 %s 成功! IP: %s", domain, ipAddr)
|
||||
domain.UpdateStatus = config.UpdatedSuccess
|
||||
} else {
|
||||
util.Log("更新域名解析 %s 失败! 异常信息: %s", domain, err)
|
||||
util.Log("更新域名解析 %s 失败! 异常信息: %s", domain, result.Status)
|
||||
domain.UpdateStatus = config.UpdatedFailed
|
||||
}
|
||||
}
|
||||
@ -215,7 +232,6 @@ func (hw *Huaweicloud) request(method string, url string, data interface{}, resu
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
util.Log("异常信息: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -75,7 +75,7 @@ func (nc *NameCheap) modify(domain *config.Domain, recordType string, ipAddr str
|
||||
err := nc.request(&result, ipAddr, domain)
|
||||
|
||||
if err != nil {
|
||||
util.Log("更新域名解析 %s 失败! 异常信息: %s", domain, result)
|
||||
util.Log("更新域名解析 %s 失败! 异常信息: %s", domain, err)
|
||||
domain.UpdateStatus = config.UpdatedFailed
|
||||
return
|
||||
}
|
||||
@ -85,7 +85,7 @@ func (nc *NameCheap) modify(domain *config.Domain, recordType string, ipAddr str
|
||||
util.Log("更新域名解析 %s 成功! IP: %s", domain, ipAddr)
|
||||
domain.UpdateStatus = config.UpdatedSuccess
|
||||
default:
|
||||
util.Log("更新域名解析 %s 失败! 异常信息: %s", domain, result)
|
||||
util.Log("更新域名解析 %s 失败! 异常信息: %s", domain, result.Status)
|
||||
domain.UpdateStatus = config.UpdatedFailed
|
||||
}
|
||||
}
|
||||
@ -105,21 +105,18 @@ func (nc *NameCheap) request(result *NameCheapResp, ipAddr string, domain *confi
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
util.Log("异常信息: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
client := util.CreateHTTPClient()
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
util.Log("异常信息: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
data, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
util.Log("异常信息: %s", err)
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -171,14 +171,12 @@ func (ns *NameSilo) request(ipAddr string, domain *config.Domain, recordID, reco
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
util.Log("异常信息: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
client := util.CreateHTTPClient()
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
util.Log("异常信息: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -126,11 +126,17 @@ func (pb *Porkbun) create(domain *config.Domain, recordType string, ipAddr strin
|
||||
&response,
|
||||
)
|
||||
|
||||
if err == nil && response.Status == "SUCCESS" {
|
||||
if err != nil {
|
||||
util.Log("新增域名解析 %s 失败! 异常信息: %s", domain, err)
|
||||
domain.UpdateStatus = config.UpdatedFailed
|
||||
return
|
||||
}
|
||||
|
||||
if response.Status == "SUCCESS" {
|
||||
util.Log("新增域名解析 %s 成功! IP: %s", domain, ipAddr)
|
||||
domain.UpdateStatus = config.UpdatedSuccess
|
||||
} else {
|
||||
util.Log("新增域名解析 %s 失败! 异常信息: %s", domain, err)
|
||||
util.Log("新增域名解析 %s 失败! 异常信息: %s", domain, response.Status)
|
||||
domain.UpdateStatus = config.UpdatedFailed
|
||||
}
|
||||
}
|
||||
@ -161,11 +167,17 @@ func (pb *Porkbun) modify(record *PorkbunDomainQueryResponse, domain *config.Dom
|
||||
&response,
|
||||
)
|
||||
|
||||
if err == nil && response.Status == "SUCCESS" {
|
||||
if err != nil {
|
||||
util.Log("更新域名解析 %s 失败! 异常信息: %s", domain, err)
|
||||
domain.UpdateStatus = config.UpdatedFailed
|
||||
return
|
||||
}
|
||||
|
||||
if response.Status == "SUCCESS" {
|
||||
util.Log("更新域名解析 %s 成功! IP: %s", domain, ipAddr)
|
||||
domain.UpdateStatus = config.UpdatedSuccess
|
||||
} else {
|
||||
util.Log("更新域名解析 %s 失败! 异常信息: %s", domain, err)
|
||||
util.Log("更新域名解析 %s 失败! 异常信息: %s", domain, response.Status)
|
||||
domain.UpdateStatus = config.UpdatedFailed
|
||||
}
|
||||
}
|
||||
@ -182,7 +194,6 @@ func (pb *Porkbun) request(url string, data interface{}, result interface{}) (er
|
||||
bytes.NewBuffer(jsonStr),
|
||||
)
|
||||
if err != nil {
|
||||
util.Log("异常信息: %s", err)
|
||||
return
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
@ -142,7 +142,14 @@ func (tc *TencentCloud) create(domain *config.Domain, recordType string, ipAddr
|
||||
record,
|
||||
&status,
|
||||
)
|
||||
if err == nil && status.Response.Error.Code == "" {
|
||||
|
||||
if err != nil {
|
||||
util.Log("新增域名解析 %s 失败! 异常信息: %s", domain, err)
|
||||
domain.UpdateStatus = config.UpdatedFailed
|
||||
return
|
||||
}
|
||||
|
||||
if status.Response.Error.Code == "" {
|
||||
util.Log("新增域名解析 %s 成功! IP: %s", domain, ipAddr)
|
||||
domain.UpdateStatus = config.UpdatedSuccess
|
||||
} else {
|
||||
@ -171,7 +178,14 @@ func (tc *TencentCloud) modify(record TencentCloudRecord, domain *config.Domain,
|
||||
record,
|
||||
&status,
|
||||
)
|
||||
if err == nil && status.Response.Error.Code == "" {
|
||||
|
||||
if err != nil {
|
||||
util.Log("更新域名解析 %s 失败! 异常信息: %s", domain, err)
|
||||
domain.UpdateStatus = config.UpdatedFailed
|
||||
return
|
||||
}
|
||||
|
||||
if status.Response.Error.Code == "" {
|
||||
util.Log("更新域名解析 %s 成功! IP: %s", domain, ipAddr)
|
||||
domain.UpdateStatus = config.UpdatedSuccess
|
||||
} else {
|
||||
@ -218,7 +232,6 @@ func (tc *TencentCloud) request(action string, data interface{}, result interfac
|
||||
bytes.NewBuffer(jsonStr),
|
||||
)
|
||||
if err != nil {
|
||||
util.Log("异常信息: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user