From 3a2be02e0af1d6bdc54f056620b26653ee48c8ba Mon Sep 17 00:00:00 2001 From: Fijxu Date: Wed, 5 Feb 2025 17:00:28 -0300 Subject: [PATCH] fix: fix logic on p.Data.Ip --- cmd/simple-ddns-client/main.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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