diff --git a/handler/dnspod_handler.go b/handler/dnspod_handler.go index 4501cb2..f236062 100644 --- a/handler/dnspod_handler.go +++ b/handler/dnspod_handler.go @@ -32,8 +32,6 @@ func (handler *DNSPodHandler) DomainLoop(domain *godns.Domain, panicChan chan<- defer func() { if err := recover(); err != nil { log.Printf("Recovered in %v: %v\n", err, debug.Stack()) - fmt.Println(godns.IdentifyPanic()) - log.Print(godns.IdentifyPanic()) panicChan <- *domain } }() diff --git a/handler/he_handler.go b/handler/he_handler.go index 69a755c..9a34e77 100644 --- a/handler/he_handler.go +++ b/handler/he_handler.go @@ -35,8 +35,6 @@ func (handler *HEHandler) DomainLoop(domain *godns.Domain, panicChan chan<- godn defer func() { if err := recover(); err != nil { log.Printf("Recovered in %v: %v\n", err, debug.Stack()) - fmt.Println(godns.IdentifyPanic()) - log.Print(godns.IdentifyPanic()) panicChan <- *domain } }() diff --git a/utils.go b/utils.go index 37a028d..1932d78 100644 --- a/utils.go +++ b/utils.go @@ -2,13 +2,9 @@ package godns import ( "errors" - "flag" - "fmt" "io/ioutil" "log" "net/http" - "runtime" - "strings" "golang.org/x/net/proxy" ) @@ -31,10 +27,9 @@ func GetCurrentIP(configuration *Settings) (string, error) { 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) + log.Println("can't connect to the proxy:", err) return "", err } @@ -56,41 +51,6 @@ func GetCurrentIP(configuration *Settings) (string, error) { return string(body), nil } -// IdentifyPanic identifies panic and output the detailed panic information -func IdentifyPanic() string { - var name, file string - var line int - var pc [16]uintptr - - n := runtime.Callers(3, pc[:]) - for _, pc := range pc[:n] { - fn := runtime.FuncForPC(pc) - if fn == nil { - continue - } - file, line = fn.FileLine(pc) - name = fn.Name() - if !strings.HasPrefix(name, "runtime.") { - break - } - } - - switch { - case name != "": - return fmt.Sprintf("%v:%v", name, line) - case file != "": - return fmt.Sprintf("%v:%v", file, line) - } - - return fmt.Sprintf("pc:%x", pc) -} - -// Usage prints the usage of GoDNS -func Usage() { - log.Println("[command] -c=[config file path]") - flag.PrintDefaults() -} - // CheckSettings check the format of settings func CheckSettings(config *Settings) error { if config.Provider == DNSPOD { diff --git a/utils_test.go b/utils_test.go index 6e2241e..fcc51b8 100644 --- a/utils_test.go +++ b/utils_test.go @@ -4,7 +4,7 @@ import ( "testing" ) -func testGetCurrentIP(t *testing.T) { +func TestGetCurrentIP(t *testing.T) { conf := &Settings{IPUrl: "http://members.3322.org/dyndns/getip"} ip, _ := GetCurrentIP(conf) @@ -14,3 +14,24 @@ func testGetCurrentIP(t *testing.T) { t.Log("IP is:" + ip) } } + +func TestCheckSettings(t *testing.T) { + settingError := &Settings{} + if err := CheckSettings(settingError); err == nil { + t.Error("setting is invalid, should return error") + } + + settingDNSPod := &Settings{Provider: "DNSPod", LoginToken: "aaa"} + if err := CheckSettings(settingDNSPod); err == nil { + t.Log("setting with login token, passed") + } else { + t.Error("setting with login token, should be passed") + } + + settingHE := &Settings{Provider: "HE", Password: ""} + if err := CheckSettings(settingHE); err != nil { + t.Log("HE setting without password, passed") + } else { + t.Error("HE setting without password, should be faild") + } +}