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

refactor: fix code lint warnings

This commit is contained in:
Timothy 2020-08-10 14:39:56 +08:00
parent e94d99e25c
commit 1ddd1dfb8b
No known key found for this signature in database
GPG Key ID: DA25A2861AA0F2D1
6 changed files with 24 additions and 18 deletions

View File

@ -49,18 +49,18 @@ func main() {
func dnsLoop() {
panicChan := make(chan godns.Domain)
log.Println("Creating DNS handler with provider:", configuration.Provider)
handler := handler.CreateHandler(configuration.Provider)
handler.SetConfiguration(&configuration)
log.Println("Creating DNS h with provider:", configuration.Provider)
h := handler.CreateHandler(configuration.Provider)
h.SetConfiguration(&configuration)
for i := range configuration.Domains {
go handler.DomainLoop(&configuration.Domains[i], panicChan)
go h.DomainLoop(&configuration.Domains[i], panicChan)
}
panicCount := 0
for {
failDomain := <-panicChan
log.Println("Got panic in goroutine, will start a new one... :", panicCount)
go handler.DomainLoop(&failDomain, panicChan)
go h.DomainLoop(&failDomain, panicChan)
panicCount++
if panicCount >= godns.PanicMax {

View File

@ -133,7 +133,7 @@ func (d *AliDNS) UpdateDomainRecord(r DomainRecord) error {
}
func (d *AliDNS) genRequestURL(parms map[string]string) string {
pArr := []string{}
var pArr []string
ps := map[string]string{}
for k, v := range publicParm {
ps[k] = v

View File

@ -14,7 +14,7 @@ import (
"time"
"github.com/TimothyYe/godns"
simplejson "github.com/bitly/go-simplejson"
"github.com/bitly/go-simplejson"
)
// Handler struct definition

View File

@ -85,6 +85,7 @@ func (handler *Handler) UpdateIP(domain, subDomain, currentIP string) {
if err != nil {
// handle error
log.Print("Failed to update sub domain:", subDomain)
return
}
defer resp.Body.Close()

View File

@ -34,8 +34,13 @@ func NewFromResolvConf(path string) (*DNSResolver, error) {
if _, err := os.Stat(path); os.IsNotExist(err) {
return &DNSResolver{}, errors.New("no such file or directory: " + path)
}
config, err := dns.ClientConfigFromFile(path)
servers := []string{}
if err != nil {
return &DNSResolver{}, err
}
var servers []string
for _, ipAddress := range config.Servers {
servers = append(servers, net.JoinHostPort(ipAddress, "53"))
}
@ -56,14 +61,14 @@ func (r *DNSResolver) lookupHost(host string, dnsType uint16, triesLeft int) ([]
switch dnsType {
case dns.TypeA:
m1.Question[0] = dns.Question{dns.Fqdn(host), dns.TypeA, dns.ClassINET}
m1.Question[0] = dns.Question{Name: dns.Fqdn(host), Qtype: dns.TypeA, Qclass: dns.ClassINET}
case dns.TypeAAAA:
m1.Question[0] = dns.Question{dns.Fqdn(host), dns.TypeAAAA, dns.ClassINET}
m1.Question[0] = dns.Question{Name: dns.Fqdn(host), Qtype: dns.TypeAAAA, Qclass: dns.ClassINET}
}
in, err := dns.Exchange(m1, r.Servers[r.r.Intn(len(r.Servers))])
result := []net.IP{}
var result []net.IP
if err != nil {
if strings.HasSuffix(err.Error(), "i/o timeout") && triesLeft > 0 {

View File

@ -17,7 +17,7 @@ import (
"github.com/miekg/dns"
"golang.org/x/net/proxy"
gomail "gopkg.in/gomail.v2"
"gopkg.in/gomail.v2"
)
var (
@ -118,10 +118,10 @@ func isIPv4(ip string) bool {
}
// GetHttpClient creates the HTTP client and return it
func GetHttpClient(configuration *Settings, use_proxy bool) *http.Client {
func GetHttpClient(configuration *Settings, useProxy bool) *http.Client {
client := &http.Client{}
if use_proxy && configuration.Socks5Proxy != "" {
if useProxy && configuration.Socks5Proxy != "" {
log.Println("use socks5 proxy:" + configuration.Socks5Proxy)
dialer, err := proxy.SOCKS5("tcp", configuration.Socks5Proxy, nil, proxy.Direct)
if err != nil {
@ -258,14 +258,14 @@ func SendTelegramNotify(configuration *Settings, domain, currentIP string) error
}
msg := buildTemplate(currentIP, domain, tpl)
url := fmt.Sprintf("https://api.telegram.org/bot%s/sendMessage?chat_id=%s&parse_mode=Markdown&text=%s",
reqURL := fmt.Sprintf("https://api.telegram.org/bot%s/sendMessage?chat_id=%s&parse_mode=Markdown&text=%s",
configuration.Notify.Telegram.BotApiKey,
configuration.Notify.Telegram.ChatId,
msg)
var response *http.Response
var err error
response, err = client.Get(url)
response, err = client.Get(reqURL)
if err != nil {
return err
@ -286,7 +286,7 @@ func SendTelegramNotify(configuration *Settings, domain, currentIP string) error
Parameters *ResponseParameters `json:"parameters"`
}
var resp APIResponse
err = json.Unmarshal([]byte(body), &resp)
err = json.Unmarshal(body, &resp)
if err != nil {
fmt.Println("error:", err)
return errors.New("failed to parse response")
@ -373,7 +373,7 @@ func SendSlackNotify(configuration *Settings, domain, currentIP string) error {
Parameters *ResponseParameters `json:"parameters"`
}
var resp APIResponse
err = json.Unmarshal([]byte(body), &resp)
err = json.Unmarshal(body, &resp)
if err != nil {
fmt.Println("error:", err)
return errors.New("failed to parse response")