1
0
mirror of https://github.com/taigrr/godns synced 2025-01-18 04:03:25 -08:00

fix lint warnings

This commit is contained in:
TimothyYe 2019-02-27 14:10:51 +08:00
parent 7e30cdf6b2
commit 4a3b2216d3
7 changed files with 29 additions and 8 deletions

View File

@ -3,7 +3,8 @@ go:
- 1.12
install:
- go get -v
- export GO111MODULE="on"
- go mod download
- go get -v github.com/smartystreets/goconvey/convey
- curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.15.0
script:

View File

@ -5,6 +5,7 @@ import (
"crypto/sha1"
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"math/rand"
@ -100,7 +101,10 @@ func (d *AliDNS) GetDomainRecords(domain, rr string) []DomainRecord {
if err != nil {
fmt.Printf("GetDomainRecords error.%+v\n", err)
} else {
json.Unmarshal(body, resp)
if err := json.Unmarshal(body, resp); err != nil {
fmt.Printf("GetDomainRecords error. %+v\n", err)
return nil
}
return resp.DomainRecords.Record
}
return nil
@ -119,6 +123,9 @@ func (d *AliDNS) UpdateDomainRecord(r DomainRecord) error {
}
urlPath := d.genRequestURL(parms)
if urlPath == "" {
return errors.New("Failed to generate request URL")
}
_, err := getHTTPBody(urlPath)
if err != nil {
fmt.Printf("UpdateDomainRecord error.%+v\n", err)
@ -152,7 +159,9 @@ func (d *AliDNS) genRequestURL(parms map[string]string) string {
s = strings.Replace(s, "%2A", "%252A", -1)
mac := hmac.New(sha1.New, []byte(d.AccessKeySecret+"&"))
mac.Write([]byte(s))
if _, err := mac.Write([]byte(s)); err != nil {
return ""
}
sign := base64.StdEncoding.EncodeToString(mac.Sum(nil))
return fmt.Sprintf("%s?%s&Signature=%s", baseURL, path, url.QueryEscape(sign))
}

View File

@ -65,7 +65,9 @@ func (handler *Handler) DomainLoop(domain *godns.Domain, panicChan chan<- godns.
// Send mail notification if notify is enabled
if handler.Configuration.Notify.Enabled {
log.Print("Sending notification to:", handler.Configuration.Notify.SendTo)
godns.SendNotify(handler.Configuration, fmt.Sprintf("%s.%s", subDomain, domain.DomainName), currentIP)
if err := godns.SendNotify(handler.Configuration, fmt.Sprintf("%s.%s", subDomain, domain.DomainName), currentIP); err != nil {
log.Printf("Failed to send notification")
}
}
}
}

View File

@ -107,7 +107,9 @@ func (handler *Handler) DomainLoop(domain *godns.Domain, panicChan chan<- godns.
// Send mail notification if notify is enabled
if handler.Configuration.Notify.Enabled {
log.Print("Sending notification to:", handler.Configuration.Notify.SendTo)
godns.SendNotify(handler.Configuration, rec.Name, currentIP)
if err := godns.SendNotify(handler.Configuration, rec.Name, currentIP); err != nil {
log.Println("Failed to send notification")
}
}
} else {
log.Printf("Record OK: %+v - %+v\r\n", rec.Name, rec.IP)

View File

@ -76,7 +76,9 @@ func (handler *Handler) DomainLoop(domain *godns.Domain, panicChan chan<- godns.
// Send mail notification if notify is enabled
if handler.Configuration.Notify.Enabled {
log.Print("Sending notification to:", handler.Configuration.Notify.SendTo)
godns.SendNotify(handler.Configuration, fmt.Sprintf("%s.%s", subDomain, domain.DomainName), currentIP)
if err := godns.SendNotify(handler.Configuration, fmt.Sprintf("%s.%s", subDomain, domain.DomainName), currentIP); err != nil {
log.Println("Failed to send notification")
}
}
} else {

View File

@ -62,7 +62,9 @@ func (handler *Handler) DomainLoop(domain *godns.Domain, panicChan chan<- godns.
// Send mail notification if notify is enabled
if handler.Configuration.Notify.Enabled {
log.Print("Sending notification to:", handler.Configuration.Notify.SendTo)
godns.SendNotify(handler.Configuration, fmt.Sprintf("%s.%s", subDomain, domain.DomainName), currentIP)
if err := godns.SendNotify(handler.Configuration, fmt.Sprintf("%s.%s", subDomain, domain.DomainName), currentIP); err != nil {
log.Println("Failed to send notificaiton")
}
}
}
}

View File

@ -217,7 +217,10 @@ func SendNotify(configuration *Settings, domain, currentIP string) error {
func buildTemplate(currentIP, domain string) string {
t := template.New("notification template")
t.Parse(mailTemplate)
if _, err := t.Parse(mailTemplate); err != nil {
log.Println("Failed to parse template")
return ""
}
data := struct {
CurrentIP string