diff --git a/cmd/simple-ddns-client/main.go b/cmd/simple-ddns-client/main.go index df5f2f5..ffedeaa 100644 --- a/cmd/simple-ddns-client/main.go +++ b/cmd/simple-ddns-client/main.go @@ -89,6 +89,12 @@ func getIpAddress() string { func (p *Porkbun) updateIp() { dnsIp, err := resolver.LookupHost(context.Background(), p.Domain) + p.Data.Ip = getIpAddress() + if p.Data.Ip == "" { + log.Print("Failed to retrieve current public IP address") + return + } + if err != nil { log.Print("Failed to retrieve IP address for domain " + p.Domain + ": " + err.Error()) return @@ -102,12 +108,6 @@ func (p *Porkbun) updateIp() { } log.Print("Current IP of the record '" + p.Domain + "' is " + dnsIp[0]) - p.Data.Ip = getIpAddress() - if p.Data.Ip == "" { - log.Print("Failed to retrieve current public IP address") - return - } - // Porkbun uses a string for the `"ttl"` key. p.Data.Ttl = string(p.Ttl) p.Data.ApiKey = &p.ApiKey