diff --git a/cmd/simple-ddns-client/main.go b/cmd/simple-ddns-client/main.go index 8811e3d..5f7929f 100644 --- a/cmd/simple-ddns-client/main.go +++ b/cmd/simple-ddns-client/main.go @@ -21,6 +21,7 @@ import ( "bytes" "context" "encoding/json" + "flag" "io" "log" "net" @@ -67,6 +68,11 @@ var resolver = &net.Resolver{ d := net.Dialer{ Timeout: time.Millisecond * time.Duration(5000), } + if config.DnsServer == "" { + // TODO: This is called two times. idk why + log.Print("\"dnsServer\" key is empty. Using default DNS server") + return d.DialContext(ctx, network, address) + } return d.DialContext(ctx, network, config.DnsServer) }, } @@ -83,7 +89,7 @@ func (p *Porkbun) updateIp() { log.Print("Failed to retrieve IP address for domain " + p.Domain) } - log.Print("Current IP of the record " + p.Domain + "is " + dnsIp[0]) + log.Print("Current IP of the record " + p.Domain + " is " + dnsIp[0]) p.Data.Ip = getIpAddress() @@ -172,7 +178,12 @@ func doPostRequest(url string, data []byte) []byte { func init() { client = &http.Client{} - config = loadConfig("/etc/simple-ddns-client/config.json") + var configPath string + + flag.StringVar(&configPath, "c", "/etc/simple-ddns-client/config.json", "config.json path") + flag.Parse() + + config = loadConfig(configPath) } func main() {