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

format code and fix the go lint warnings

This commit is contained in:
TimothyYe 2018-12-07 16:04:59 +08:00
parent fb5c679bf7
commit 4c82260c4d
5 changed files with 47 additions and 40 deletions

View File

@ -255,7 +255,7 @@ docker run -d --name godns --restart=always \
-v /path/to/config.json:/usr/local/godns/config.json timothyye/godns:latest -v /path/to/config.json:/usr/local/godns/config.json timothyye/godns:latest
``` ```
## Run it as an Windows service ## Run it as a Windows service
* Get [birkett/srvany-ng](https://github.com/birkett/srvany-ng/releases) from Github. * Get [birkett/srvany-ng](https://github.com/birkett/srvany-ng/releases) from Github.
* Uncompress and place the executable `srvany-ng.exe` to the same directory where `godns.exe` in. * Uncompress and place the executable `srvany-ng.exe` to the same directory where `godns.exe` in.

View File

@ -83,7 +83,7 @@ func (handler *CloudflareHandler) DomainLoop(domain *godns.Domain, panicChan cha
} }
log.Println("Current IP is:", currentIP) log.Println("Current IP is:", currentIP)
//check against locally cached IP, if no change, skip update //check against locally cached IP, if no change, skip update
if (currentIP == lastIP){ if currentIP == lastIP {
log.Printf("IP is the same as cached one. Skip update.\n") log.Printf("IP is the same as cached one. Skip update.\n")
} else { } else {
lastIP = currentIP lastIP = currentIP

View File

@ -54,7 +54,7 @@ func (handler *DNSPodHandler) DomainLoop(domain *godns.Domain, panicChan chan<-
log.Println("currentIP is:", currentIP) log.Println("currentIP is:", currentIP)
//check against locally cached IP, if no change, skip update //check against locally cached IP, if no change, skip update
if (currentIP == lastIP){ if currentIP == lastIP {
log.Printf("IP is the same as cached one. Skip update.\n") log.Printf("IP is the same as cached one. Skip update.\n")
} else { } else {
lastIP = currentIP lastIP = currentIP

View File

@ -50,7 +50,7 @@ func (handler *HEHandler) DomainLoop(domain *godns.Domain, panicChan chan<- godn
log.Println("currentIP is:", currentIP) log.Println("currentIP is:", currentIP)
//check against locally cached IP, if no change, skip update //check against locally cached IP, if no change, skip update
if (currentIP == lastIP){ if currentIP == lastIP {
log.Printf("IP is the same as cached one. Skip update.\n") log.Printf("IP is the same as cached one. Skip update.\n")
} else { } else {
lastIP = currentIP lastIP = currentIP

View File

@ -6,9 +6,9 @@ import (
"html/template" "html/template"
"io/ioutil" "io/ioutil"
"log" "log"
"net"
"net/http" "net/http"
"strings" "strings"
"net"
"golang.org/x/net/proxy" "golang.org/x/net/proxy"
"gopkg.in/gomail.v2" "gopkg.in/gomail.v2"
@ -52,7 +52,7 @@ func GetIPFromInterface(configuration *Settings) (string,error) {
return "", err return "", err
} }
addrs, err :=ifaces.Addrs(); addrs, err := ifaces.Addrs()
if err != nil { if err != nil {
log.Println("can't get address from "+configuration.IPInterface+":", err) log.Println("can't get address from "+configuration.IPInterface+":", err)
return "", err return "", err
@ -66,12 +66,18 @@ func GetIPFromInterface(configuration *Settings) (string,error) {
case *net.IPAddr: case *net.IPAddr:
ip = v.IP ip = v.IP
} }
if (ip == nil){ if ip == nil {
continue; continue
} }
if (!(ip.IsGlobalUnicast() &&!(ip.IsUnspecified()||ip.IsMulticast()||ip.IsLoopback()||ip.IsLinkLocalUnicast()||ip.IsLinkLocalMulticast()||ip.IsInterfaceLocalMulticast()))){ if !(ip.IsGlobalUnicast() &&
continue; !(ip.IsUnspecified() ||
ip.IsMulticast() ||
ip.IsLoopback() ||
ip.IsLinkLocalUnicast() ||
ip.IsLinkLocalMulticast() ||
ip.IsInterfaceLocalMulticast())) {
continue
} }
//the code is not ready for updating an AAAA record //the code is not ready for updating an AAAA record
@ -85,8 +91,8 @@ func GetIPFromInterface(configuration *Settings) (string,error) {
continue; continue;
} }
} */ } */
if (!isIPv4(ip.String())){ if !isIPv4(ip.String()) {
continue; continue
} }
return ip.String(), nil return ip.String(), nil
@ -103,18 +109,18 @@ func isIPv4(ip string) bool{
func GetCurrentIP(configuration *Settings) (string, error) { func GetCurrentIP(configuration *Settings) (string, error) {
var err error var err error
if (configuration.IPUrl != ""){ if configuration.IPUrl != "" {
ip, err := GetIPOnline(configuration) ip, err := GetIPOnline(configuration)
if (err != nil){ if err != nil {
log.Println("get ip online failed. Fallback to get ip from interface if possible.") log.Println("get ip online failed. Fallback to get ip from interface if possible.")
} else { } else {
return ip, nil return ip, nil
} }
} }
if (configuration.IPInterface != ""){ if configuration.IPInterface != "" {
ip, err := GetIPFromInterface(configuration) ip, err := GetIPFromInterface(configuration)
if (err != nil){ if err != nil {
log.Println("get ip from interface failed. There is no more ways to try.") log.Println("get ip from interface failed. There is no more ways to try.")
} else { } else {
return ip, nil return ip, nil
@ -123,6 +129,7 @@ func GetCurrentIP(configuration *Settings) (string, error) {
return "", err return "", err
} }
// GetIPOnline gets public IP from internet // GetIPOnline gets public IP from internet
func GetIPOnline(configuration *Settings) (string, error) { func GetIPOnline(configuration *Settings) (string, error) {
client := &http.Client{} client := &http.Client{}