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

fix golint warnings

This commit is contained in:
Timothy 2017-10-26 18:11:38 +08:00
parent d3f82cffe6
commit 622b77d431
6 changed files with 26 additions and 13 deletions

View File

@ -16,8 +16,10 @@ import (
"golang.org/x/net/proxy"
)
//DNSPodHandler struct definition
type DNSPodHandler struct{}
//DomainLoop the main logic loop
func (handler *DNSPodHandler) DomainLoop(domain *Domain, panicChan chan<- Domain) {
defer func() {
if err := recover(); err != nil {
@ -67,6 +69,7 @@ func (handler *DNSPodHandler) DomainLoop(domain *Domain, panicChan chan<- Domain
}
}
//GenerateHeader generates the request header for DNSPod API
func (handler *DNSPodHandler) GenerateHeader(content url.Values) url.Values {
header := url.Values{}
if configuration.LoginToken != "" {
@ -88,6 +91,7 @@ func (handler *DNSPodHandler) GenerateHeader(content url.Values) url.Values {
return header
}
//GetDomain returns specific domain by name
func (handler *DNSPodHandler) GetDomain(name string) int64 {
var ret int64
@ -136,6 +140,7 @@ func (handler *DNSPodHandler) GetDomain(name string) int64 {
return ret
}
//GetSubDomain returns subdomain by domain id
func (handler *DNSPodHandler) GetSubDomain(domainID int64, name string) (string, string) {
log.Println("debug:", domainID, name)
var ret, ip string
@ -180,6 +185,7 @@ func (handler *DNSPodHandler) GetSubDomain(domainID int64, name string) (string,
return ret, ip
}
//UpdateIP update subdomain with current IP
func (handler *DNSPodHandler) UpdateIP(domainID int64, subDomainID string, subDomainName string, ip string) {
value := url.Values{}
value.Add("domain_id", strconv.FormatInt(domainID, 10))
@ -210,6 +216,7 @@ func (handler *DNSPodHandler) UpdateIP(domainID int64, subDomainID string, subDo
}
//PostData post data and invoke DNSPod API
func (handler *DNSPodHandler) PostData(url string, content url.Values) (string, error) {
client := &http.Client{}

View File

@ -8,13 +8,13 @@ import (
)
const (
// PANIC_MAX is the max allowed panic times
PANIC_MAX = 5
// PanicMax is the max allowed panic times
PanicMax = 5
// INTERVAL is minute
INTERVAL = 5
// DNSPOD
// DNSPOD for dnspod.cn
DNSPOD = "DNSPod"
// HE
// HE for he.net
HE = "HE"
)
@ -68,7 +68,7 @@ func dnsLoop() {
}
panicCount++
if panicCount >= PANIC_MAX {
if panicCount >= PanicMax {
os.Exit(1)
}
}

View File

@ -1,5 +1,6 @@
package main
//IHandler is the interface for all DNS handlers
type IHandler interface {
DomainLoop(domain *Domain, panicChan chan<- Domain)
}

View File

@ -14,11 +14,14 @@ import (
)
var (
//HEUrl the API address for he.net
HEUrl = "https://dyn.dns.he.net/nic/update"
)
//HEHandler struct
type HEHandler struct{}
//DomainLoop the main logic loop
func (handler *HEHandler) DomainLoop(domain *Domain, panicChan chan<- Domain) {
defer func() {
if err := recover(); err != nil {
@ -48,6 +51,7 @@ func (handler *HEHandler) DomainLoop(domain *Domain, panicChan chan<- Domain) {
}
}
//UpdateIP update subdomain with current IP
func (handler *HEHandler) UpdateIP(domain, subDomain, currentIP string) {
values := url.Values{}
values.Add("hostname", fmt.Sprintf("%s.%s", subDomain, domain))

View File

@ -48,7 +48,7 @@ type Logger struct {
// NewLogger returns a new created logger
func NewLogger(logfile string, size, num int, level int, flushInterval int64, flushSize int) (logger *Logger, err error) {
if size < 1 || num < 1 || level < L_INFO || len(logfile) < 1 {
err = errors.New("NewLogWriter:param error.")
err = errors.New("newLogWriter:param error")
return
}
logger = &Logger{size: size * 1024, num: num, level: level, DEV_MODE: false}

View File

@ -9,22 +9,23 @@ import (
"net/http"
"runtime"
"strings"
"golang.org/x/net/proxy"
)
func getCurrentIP(url string) (string, error) {
client := &http.Client{}
if configuration.Socks5Proxy != "" {
log.Println("use socks5 proxy:" + configuration.Socks5Proxy)
dialer, err := proxy.SOCKS5("tcp", configuration.Socks5Proxy, nil, proxy.Direct)
if err != nil {
fmt.Println("can't connect to the proxy:", err)
return "", err
}
httpTransport := &http.Transport{}
client.Transport = httpTransport
httpTransport.Dial = dialer.Dial
@ -79,14 +80,14 @@ func usage() {
func checkSettings(config *Settings) error {
if config.Provider == DNSPOD {
if (config.Email == "" || config.Password == "") && config.LoginToken == "" {
return errors.New("Email/Password or login token cannot be empty!")
return errors.New("email/password or login token cannot be empty")
}
} else if config.Provider == HE {
if config.Password == "" {
return errors.New("Password cannot be empty!")
return errors.New("password cannot be empty")
}
} else {
return errors.New("Please provide supported DNS provider: DNSPod/HE")
return errors.New("please provide supported DNS provider: DNSPod/HE")
}
return nil