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-01-22 20:35:45 +08:00
parent 57b3c4c79d
commit dc376d91b4
6 changed files with 31 additions and 30 deletions

View File

@ -76,6 +76,7 @@ func getHTTPBody(url string) ([]byte, error) {
return nil, fmt.Errorf("Status %d, Error:%s", resp.StatusCode, body) return nil, fmt.Errorf("Status %d, Error:%s", resp.StatusCode, body)
} }
// NewAliDNS function creates instance of AliDNS and return
func NewAliDNS(key, secret string) *AliDNS { func NewAliDNS(key, secret string) *AliDNS {
once.Do(func() { once.Do(func() {
instance = &AliDNS{ instance = &AliDNS{

View File

@ -9,18 +9,18 @@ import (
"github.com/TimothyYe/godns" "github.com/TimothyYe/godns"
) )
// AliDNSHandler struct // Handler struct
type AliDNSHandler struct { type Handler struct {
Configuration *godns.Settings Configuration *godns.Settings
} }
// SetConfiguration pass dns settings and store it to handler instance // SetConfiguration pass dns settings and store it to handler instance
func (handler *AliDNSHandler) SetConfiguration(conf *godns.Settings) { func (handler *Handler) SetConfiguration(conf *godns.Settings) {
handler.Configuration = conf handler.Configuration = conf
} }
// DomainLoop the main logic loop // DomainLoop the main logic loop
func (handler *AliDNSHandler) DomainLoop(domain *godns.Domain, panicChan chan<- godns.Domain) { func (handler *Handler) DomainLoop(domain *godns.Domain, panicChan chan<- godns.Domain) {
defer func() { defer func() {
if err := recover(); err != nil { if err := recover(); err != nil {
log.Printf("Recovered in %v: %v\n", err, debug.Stack()) log.Printf("Recovered in %v: %v\n", err, debug.Stack())

View File

@ -15,8 +15,8 @@ import (
"golang.org/x/net/proxy" "golang.org/x/net/proxy"
) )
// CloudflareHandler struct definition // Handler struct definition
type CloudflareHandler struct { type Handler struct {
Configuration *godns.Settings Configuration *godns.Settings
API string API string
} }
@ -61,13 +61,13 @@ type Zone struct {
} }
// SetConfiguration pass dns settings and store it to handler instance // SetConfiguration pass dns settings and store it to handler instance
func (handler *CloudflareHandler) SetConfiguration(conf *godns.Settings) { func (handler *Handler) SetConfiguration(conf *godns.Settings) {
handler.Configuration = conf handler.Configuration = conf
handler.API = "https://api.cloudflare.com/client/v4" handler.API = "https://api.cloudflare.com/client/v4"
} }
// DomainLoop the main logic loop // DomainLoop the main logic loop
func (handler *CloudflareHandler) DomainLoop(domain *godns.Domain, panicChan chan<- godns.Domain) { func (handler *Handler) DomainLoop(domain *godns.Domain, panicChan chan<- godns.Domain) {
defer func() { defer func() {
if err := recover(); err != nil { if err := recover(); err != nil {
log.Printf("Recovered in %v: %v\n", err, debug.Stack()) log.Printf("Recovered in %v: %v\n", err, debug.Stack())
@ -136,7 +136,7 @@ func recordTracked(domain *godns.Domain, record *DNSRecord) bool {
} }
// Create a new request with auth in place and optional proxy // Create a new request with auth in place and optional proxy
func (handler *CloudflareHandler) newRequest(method, url string, body io.Reader) (*http.Request, *http.Client) { func (handler *Handler) newRequest(method, url string, body io.Reader) (*http.Request, *http.Client) {
client := &http.Client{} client := &http.Client{}
if handler.Configuration.Socks5Proxy != "" { if handler.Configuration.Socks5Proxy != "" {
@ -159,7 +159,7 @@ func (handler *CloudflareHandler) newRequest(method, url string, body io.Reader)
} }
// Find the correct zone via domain name // Find the correct zone via domain name
func (handler *CloudflareHandler) getZone(domain string) string { func (handler *Handler) getZone(domain string) string {
var z ZoneResponse var z ZoneResponse
@ -191,7 +191,7 @@ func (handler *CloudflareHandler) getZone(domain string) string {
} }
// Get all DNS A records for a zone // Get all DNS A records for a zone
func (handler *CloudflareHandler) getDNSRecords(zoneID string) []DNSRecord { func (handler *Handler) getDNSRecords(zoneID string) []DNSRecord {
var empty []DNSRecord var empty []DNSRecord
var r DNSRecordResponse var r DNSRecordResponse
@ -220,7 +220,7 @@ func (handler *CloudflareHandler) getDNSRecords(zoneID string) []DNSRecord {
} }
// Update DNS A Record with new IP // Update DNS A Record with new IP
func (handler *CloudflareHandler) updateRecord(record DNSRecord, newIP string) { func (handler *Handler) updateRecord(record DNSRecord, newIP string) {
var r DNSRecordUpdateResponse var r DNSRecordUpdateResponse
record.SetIP(newIP) record.SetIP(newIP)

View File

@ -17,18 +17,18 @@ import (
"golang.org/x/net/proxy" "golang.org/x/net/proxy"
) )
// DNSPodHandler struct definition // Handler struct definition
type DNSPodHandler struct { type Handler struct {
Configuration *godns.Settings Configuration *godns.Settings
} }
// SetConfiguration pass dns settings and store it to handler instance // SetConfiguration pass dns settings and store it to handler instance
func (handler *DNSPodHandler) SetConfiguration(conf *godns.Settings) { func (handler *Handler) SetConfiguration(conf *godns.Settings) {
handler.Configuration = conf handler.Configuration = conf
} }
// DomainLoop the main logic loop // DomainLoop the main logic loop
func (handler *DNSPodHandler) DomainLoop(domain *godns.Domain, panicChan chan<- godns.Domain) { func (handler *Handler) DomainLoop(domain *godns.Domain, panicChan chan<- godns.Domain) {
defer func() { defer func() {
if err := recover(); err != nil { if err := recover(); err != nil {
log.Printf("Recovered in %v: %v\n", err, debug.Stack()) log.Printf("Recovered in %v: %v\n", err, debug.Stack())
@ -91,7 +91,7 @@ func (handler *DNSPodHandler) DomainLoop(domain *godns.Domain, panicChan chan<-
} }
// GenerateHeader generates the request header for DNSPod API // GenerateHeader generates the request header for DNSPod API
func (handler *DNSPodHandler) GenerateHeader(content url.Values) url.Values { func (handler *Handler) GenerateHeader(content url.Values) url.Values {
header := url.Values{} header := url.Values{}
if handler.Configuration.LoginToken != "" { if handler.Configuration.LoginToken != "" {
header.Add("login_token", handler.Configuration.LoginToken) header.Add("login_token", handler.Configuration.LoginToken)
@ -111,7 +111,7 @@ func (handler *DNSPodHandler) GenerateHeader(content url.Values) url.Values {
} }
// GetDomain returns specific domain by name // GetDomain returns specific domain by name
func (handler *DNSPodHandler) GetDomain(name string) int64 { func (handler *Handler) GetDomain(name string) int64 {
var ret int64 var ret int64
values := url.Values{} values := url.Values{}
@ -160,7 +160,7 @@ func (handler *DNSPodHandler) GetDomain(name string) int64 {
} }
// GetSubDomain returns subdomain by domain id // GetSubDomain returns subdomain by domain id
func (handler *DNSPodHandler) GetSubDomain(domainID int64, name string) (string, string) { func (handler *Handler) GetSubDomain(domainID int64, name string) (string, string) {
log.Println("debug:", domainID, name) log.Println("debug:", domainID, name)
var ret, ip string var ret, ip string
value := url.Values{} value := url.Values{}
@ -205,7 +205,7 @@ func (handler *DNSPodHandler) GetSubDomain(domainID int64, name string) (string,
} }
// UpdateIP update subdomain with current IP // UpdateIP update subdomain with current IP
func (handler *DNSPodHandler) UpdateIP(domainID int64, subDomainID string, subDomainName string, ip string) { func (handler *Handler) UpdateIP(domainID int64, subDomainID string, subDomainName string, ip string) {
value := url.Values{} value := url.Values{}
value.Add("domain_id", strconv.FormatInt(domainID, 10)) value.Add("domain_id", strconv.FormatInt(domainID, 10))
value.Add("record_id", subDomainID) value.Add("record_id", subDomainID)
@ -236,7 +236,7 @@ func (handler *DNSPodHandler) UpdateIP(domainID int64, subDomainID string, subDo
} }
// PostData post data and invoke DNSPod API // PostData post data and invoke DNSPod API
func (handler *DNSPodHandler) PostData(url string, content url.Values) (string, error) { func (handler *Handler) PostData(url string, content url.Values) (string, error) {
client := &http.Client{} client := &http.Client{}
if handler.Configuration.Socks5Proxy != "" { if handler.Configuration.Socks5Proxy != "" {

View File

@ -20,13 +20,13 @@ func CreateHandler(provider string) IHandler {
switch provider { switch provider {
case godns.CLOUDFLARE: case godns.CLOUDFLARE:
handler = IHandler(&cloudflare.CloudflareHandler{}) handler = IHandler(&cloudflare.Handler{})
case godns.DNSPOD: case godns.DNSPOD:
handler = IHandler(&dnspod.DNSPodHandler{}) handler = IHandler(&dnspod.Handler{})
case godns.HE: case godns.HE:
handler = IHandler(&he.HEHandler{}) handler = IHandler(&he.Handler{})
case godns.ALIDNS: case godns.ALIDNS:
handler = IHandler(&alidns.AliDNSHandler{}) handler = IHandler(&alidns.Handler{})
} }
return handler return handler

View File

@ -20,18 +20,18 @@ var (
HEUrl = "https://dyn.dns.he.net/nic/update" HEUrl = "https://dyn.dns.he.net/nic/update"
) )
// HEHandler struct // Handler struct
type HEHandler struct { type Handler struct {
Configuration *godns.Settings Configuration *godns.Settings
} }
// SetConfiguration pass dns settings and store it to handler instance // SetConfiguration pass dns settings and store it to handler instance
func (handler *HEHandler) SetConfiguration(conf *godns.Settings) { func (handler *Handler) SetConfiguration(conf *godns.Settings) {
handler.Configuration = conf handler.Configuration = conf
} }
// DomainLoop the main logic loop // DomainLoop the main logic loop
func (handler *HEHandler) DomainLoop(domain *godns.Domain, panicChan chan<- godns.Domain) { func (handler *Handler) DomainLoop(domain *godns.Domain, panicChan chan<- godns.Domain) {
defer func() { defer func() {
if err := recover(); err != nil { if err := recover(); err != nil {
log.Printf("Recovered in %v: %v\n", err, debug.Stack()) log.Printf("Recovered in %v: %v\n", err, debug.Stack())
@ -74,7 +74,7 @@ func (handler *HEHandler) DomainLoop(domain *godns.Domain, panicChan chan<- godn
} }
// UpdateIP update subdomain with current IP // UpdateIP update subdomain with current IP
func (handler *HEHandler) UpdateIP(domain, subDomain, currentIP string) { func (handler *Handler) UpdateIP(domain, subDomain, currentIP string) {
values := url.Values{} values := url.Values{}
values.Add("hostname", fmt.Sprintf("%s.%s", subDomain, domain)) values.Add("hostname", fmt.Sprintf("%s.%s", subDomain, domain))
values.Add("password", handler.Configuration.Password) values.Add("password", handler.Configuration.Password)