Skip to content

Commit

Permalink
chore: remove unused params and unnecessary nil checks (#1052)
Browse files Browse the repository at this point in the history
  • Loading branch information
WaterLemons2k authored Mar 22, 2024
1 parent 77caa37 commit ead4e1d
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 21 deletions.
6 changes: 3 additions & 3 deletions dns/cloudflare.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (cf *Cloudflare) addUpdateDomainRecords(recordType string) {

if len(records.Result) > 0 {
// 更新
cf.modify(records, zoneID, domain, recordType, ipAddr)
cf.modify(records, zoneID, domain, ipAddr)
} else {
// 新增
cf.create(zoneID, domain, recordType, ipAddr)
Expand Down Expand Up @@ -180,7 +180,7 @@ func (cf *Cloudflare) create(zoneID string, domain *config.Domain, recordType st
}

// 修改
func (cf *Cloudflare) modify(result CloudflareRecordsResp, zoneID string, domain *config.Domain, recordType string, ipAddr string) {
func (cf *Cloudflare) modify(result CloudflareRecordsResp, zoneID string, domain *config.Domain, ipAddr string) {
for _, record := range result.Result {
// 相同不修改
if record.Content == ipAddr {
Expand All @@ -207,7 +207,7 @@ func (cf *Cloudflare) modify(result CloudflareRecordsResp, zoneID string, domain
return
}

if err == nil && status.Success {
if status.Success {
util.Log("更新域名解析 %s 成功! IP: %s", domain, ipAddr)
domain.UpdateStatus = config.UpdatedSuccess
} else {
Expand Down
10 changes: 5 additions & 5 deletions dns/dnspod.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,15 @@ func (dnspod *Dnspod) create(domain *config.Domain, recordType string, ipAddr st
params.Set("record_line", "默认")
}

status, err := dnspod.commonRequest(recordCreateAPI, params, domain)
status, err := dnspod.request(recordCreateAPI, params)

if err != nil {
util.Log("新增域名解析 %s 失败! 异常信息: %s", domain, err)
domain.UpdateStatus = config.UpdatedFailed
return
}

if err == nil && status.Status.Code == "1" {
if status.Status.Code == "1" {
util.Log("新增域名解析 %s 成功! IP: %s", domain, ipAddr)
domain.UpdateStatus = config.UpdatedSuccess
} else {
Expand Down Expand Up @@ -155,7 +155,7 @@ func (dnspod *Dnspod) modify(record DnspodRecord, domain *config.Domain, recordT
params.Set("record_line", "默认")
}

status, err := dnspod.commonRequest(recordModifyURL, params, domain)
status, err := dnspod.request(recordModifyURL, params)

if err != nil {
util.Log("更新域名解析 %s 失败! 异常信息: %s", domain, err)
Expand All @@ -172,8 +172,8 @@ func (dnspod *Dnspod) modify(record DnspodRecord, domain *config.Domain, recordT
}
}

// 公共
func (dnspod *Dnspod) commonRequest(apiAddr string, values url.Values, domain *config.Domain) (status DnspodStatus, err error) {
// request sends a POST request to the given API with the given values.
func (dnspod *Dnspod) request(apiAddr string, values url.Values) (status DnspodStatus, err error) {
client := util.CreateHTTPClient()
resp, err := client.PostForm(
apiAddr,
Expand Down
4 changes: 2 additions & 2 deletions dns/google_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ func (gd *GoogleDomain) addUpdateDomainRecords(recordType string) {
}

for _, domain := range domains {
gd.modify(domain, recordType, ipAddr)
gd.modify(domain, ipAddr)
}
}

// 修改
func (gd *GoogleDomain) modify(domain *config.Domain, recordType string, ipAddr string) {
func (gd *GoogleDomain) modify(domain *config.Domain, ipAddr string) {
params := domain.GetCustomParams()
params.Set("hostname", domain.GetFullDomain())
params.Set("myip", ipAddr)
Expand Down
4 changes: 2 additions & 2 deletions dns/huawei.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (hw *Huaweicloud) addUpdateDomainRecords(recordType string) {
// 名称相同才更新。华为云默认是模糊搜索
if record.Name == domain.String()+"." {
// 更新
hw.modify(record, domain, recordType, ipAddr)
hw.modify(record, domain, ipAddr)
find = true
break
}
Expand Down Expand Up @@ -170,7 +170,7 @@ func (hw *Huaweicloud) create(domain *config.Domain, recordType string, ipAddr s
}

// 修改
func (hw *Huaweicloud) modify(record HuaweicloudRecordsets, domain *config.Domain, recordType string, ipAddr string) {
func (hw *Huaweicloud) modify(record HuaweicloudRecordsets, domain *config.Domain, ipAddr string) {

// 相同不修改
if len(record.Records) > 0 && record.Records[0] == ipAddr {
Expand Down
4 changes: 2 additions & 2 deletions dns/namecheap.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ func (nc *NameCheap) addUpdateDomainRecords(recordType string) {
}

for _, domain := range domains {
nc.modify(domain, recordType, ipAddr)
nc.modify(domain, ipAddr)
}
}

// 修改
func (nc *NameCheap) modify(domain *config.Domain, recordType string, ipAddr string) {
func (nc *NameCheap) modify(domain *config.Domain, ipAddr string) {
var result NameCheapResp
err := nc.request(&result, ipAddr, domain)

Expand Down
8 changes: 3 additions & 5 deletions util/update/detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,9 @@ func findAssetForArch(arch string, rel *Release,
// 从 release 列表中查找最新的版本。
// GitHub API 返回的列表按照创建日期的顺序排列。
if a, v, ok := findAssetFromRelease(rel, getSuffixes(arch)); ok {
if release == nil || v.GreaterThan(version) {
version = v
asset = a
release = rel
}
version = v
asset = a
release = rel
}

if release == nil {
Expand Down
2 changes: 1 addition & 1 deletion util/update/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func to(assetURL, assetFileName, cmdPath string) error {
return err
}
defer src.Close()
return decompressAndUpdate(src, assetFileName, assetURL, cmdPath)
return decompressAndUpdate(src, assetFileName, cmdPath)
}

func downloadAssetFromURL(url string) (rc io.ReadCloser, err error) {
Expand Down
2 changes: 1 addition & 1 deletion util/update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"path/filepath"
)

func decompressAndUpdate(src io.Reader, assetName, assetURL, cmdPath string) error {
func decompressAndUpdate(src io.Reader, assetName, cmdPath string) error {
_, cmd := filepath.Split(cmdPath)
asset, err := decompressCommand(src, assetName, cmd)
if err != nil {
Expand Down

0 comments on commit ead4e1d

Please sign in to comment.