Skip to content

Commit

Permalink
optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
jie authored and jie committed Sep 1, 2020
1 parent 3072ec1 commit 9f91ea8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 50 deletions.
12 changes: 6 additions & 6 deletions dns/alidns.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ func (ali *Alidns) addUpdateDomainRecords(recordType string) {
request.RecordId = record.RecordId

updateResp, err := ali.client.UpdateDomainRecord(request)
if err != nil || !updateResp.BaseResponse.IsSuccess() {
log.Printf("更新域名解析 %s 失败!IP: %s, Error: %s, Response: %s", domain, ipAddr, err, updateResp.GetHttpContentString())
} else {
if err == nil && updateResp.BaseResponse.IsSuccess() {
log.Printf("更新域名解析 %s 成功!IP: %s", domain, ipAddr)
} else {
log.Printf("更新域名解析 %s 失败!IP: %s, Error: %s, Response: %s", domain, ipAddr, err, updateResp.GetHttpContentString())
}
}
} else {
Expand All @@ -87,10 +87,10 @@ func (ali *Alidns) addUpdateDomainRecords(recordType string) {
request.DomainName = domain.DomainName

createResp, err := ali.client.AddDomainRecord(request)
if err != nil || !createResp.BaseResponse.IsSuccess() {
log.Printf("新增域名解析 %s 失败!IP: %s, Error: %s, Response: %s", domain, ipAddr, err, createResp.GetHttpContentString())
} else {
if err == nil && createResp.BaseResponse.IsSuccess() {
log.Printf("新增域名解析 %s 成功!IP: %s", domain, ipAddr)
} else {
log.Printf("新增域名解析 %s 失败!IP: %s, Error: %s, Response: %s", domain, ipAddr, err, createResp.GetHttpContentString())
}
}
}
Expand Down
55 changes: 11 additions & 44 deletions dns/dnspod.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package dns

import (
"ddns-go/config"
"encoding/json"
"io/ioutil"
"ddns-go/util"
"log"
"net/http"
"net/url"
Expand Down Expand Up @@ -98,12 +97,10 @@ func (dnspod *Dnspod) create(result DnspodRecordListResp, domain *Domain, record
},
domain,
)
if err != nil {
if status.Status.Code == "1" {
log.Printf("新增域名解析 %s 成功!IP: %s", domain, ipAddr)
} else {
log.Printf("新增域名解析 %s 失败!Code: %s, Message: %s", domain, status.Status.Code, status.Status.Message)
}
if err == nil && status.Status.Code == "1" {
log.Printf("新增域名解析 %s 成功!IP: %s", domain, ipAddr)
} else {
log.Printf("新增域名解析 %s 失败!Code: %s, Message: %s", domain, status.Status.Code, status.Status.Message)
}
}

Expand All @@ -128,12 +125,10 @@ func (dnspod *Dnspod) modify(result DnspodRecordListResp, domain *Domain, record
},
domain,
)
if err != nil {
if status.Status.Code == "1" {
log.Printf("更新域名解析 %s 成功!IP: %s", domain, ipAddr)
} else {
log.Printf("更新域名解析 %s 失败!Code: %s, Message: %s", domain, status.Status.Code, status.Status.Message)
}
if err == nil && status.Status.Code == "1" {
log.Printf("更新域名解析 %s 成功!IP: %s", domain, ipAddr)
} else {
log.Printf("更新域名解析 %s 失败!Code: %s, Message: %s", domain, status.Status.Code, status.Status.Message)
}
}
}
Expand All @@ -145,23 +140,8 @@ func (dnspod *Dnspod) commonRequest(apiAddr string, values url.Values, domain *D
values,
)

if err != nil {
log.Printf("请求接口%s失败! ERROR: %s\n", apiAddr, err)
return
}

defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Printf("请求接口%s失败! ERROR: %s\n", apiAddr, err)
return
}
util.GetHTTPResponse(resp, apiAddr, err, &status)

err = json.Unmarshal(body, &status)

if err != nil {
log.Printf("请求接口%s解析json结果失败! ERROR: %s\n", apiAddr, err)
}
return
}

Expand All @@ -176,21 +156,8 @@ func (dnspod *Dnspod) getRecordList(domain *Domain, typ string) (result DnspodRe
"record_type": {typ},
},
)
if err != nil {
log.Printf("请求接口%s失败! ERROR: %s\n", recordListAPI, err)
} else {
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Printf("请求接口%s失败! ERROR: %s\n", recordListAPI, err)
}

err = json.Unmarshal(body, &result)
util.GetHTTPResponse(resp, recordListAPI, err, &result)

if err != nil {
log.Printf("请求接口%s解析json结果失败! ERROR: %s\n", recordListAPI, err)
}

}
return
}

0 comments on commit 9f91ea8

Please sign in to comment.