From ad9c69427c2506dfa42e906a65be779e6a5253bc Mon Sep 17 00:00:00 2001 From: Chris Gianelloni Date: Fri, 28 Feb 2025 17:19:05 -0500 Subject: [PATCH] fix: use errors, strconv, and string concatenation to avoid fmt Signed-off-by: Chris Gianelloni --- cmd/cdnsd/main.go | 5 +---- internal/dns/dns.go | 11 +++++------ internal/indexer/indexer.go | 8 +++----- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/cmd/cdnsd/main.go b/cmd/cdnsd/main.go index c20f0eb..6245dcd 100644 --- a/cmd/cdnsd/main.go +++ b/cmd/cdnsd/main.go @@ -113,10 +113,7 @@ func main() { cfg.Metrics.ListenPort, ) slog.Info( - fmt.Sprintf( - "starting listener for prometheus metrics connections on %s", - metricsListenAddr, - ), + "starting listener for prometheus metrics connections on " + metricsListenAddr, ) metricsMux := http.NewServeMux() metricsMux.Handle("/metrics", promhttp.Handler()) diff --git a/internal/dns/dns.go b/internal/dns/dns.go index 48a8fa1..af38510 100644 --- a/internal/dns/dns.go +++ b/internal/dns/dns.go @@ -8,11 +8,13 @@ package dns import ( "crypto/rand" + "errors" "fmt" "log/slog" "math/big" "net" "os" + "strconv" "strings" "github.com/blinklabs-io/cdnsd/internal/config" @@ -38,10 +40,7 @@ func Start() error { cfg.Dns.ListenPort, ) slog.Info( - fmt.Sprintf( - "starting DNS listener on %s", - listenAddr, - ), + "starting DNS listener on " + listenAddr, ) // Setup handler dns.HandleFunc(".", handleQuery) @@ -289,7 +288,7 @@ func handleQuery(w dns.ResponseWriter, r *dns.Msg) { func stateRecordToDnsRR(record state.DomainRecord) (dns.RR, error) { tmpTtl := "" if record.Ttl > 0 { - tmpTtl = fmt.Sprintf("%d", record.Ttl) + tmpTtl = strconv.Itoa(record.Ttl) } tmpRR := fmt.Sprintf( "%s %s IN %s %s", @@ -358,7 +357,7 @@ func doQuery(msg *dns.Msg, address string, recursive bool) (*dns.Msg, error) { return nil, err } if resp == nil { - return nil, fmt.Errorf("dns response empty") + return nil, errors.New("dns response empty") } slog.Debug( fmt.Sprintf( diff --git a/internal/indexer/indexer.go b/internal/indexer/indexer.go index b39110f..a0d6fe3 100644 --- a/internal/indexer/indexer.go +++ b/internal/indexer/indexer.go @@ -8,6 +8,7 @@ package indexer import ( "encoding/hex" + "errors" "fmt" "log/slog" "math" @@ -371,7 +372,7 @@ func (i *Indexer) handleEventOutputDns( } if record.Ttl.HasValue() { if record.Ttl.Value > math.MaxInt { - return fmt.Errorf("record ttl value out of bounds") + return errors.New("record ttl value out of bounds") } tmpRecord.Ttl = int(record.Ttl.Value) // #nosec G115 } @@ -381,10 +382,7 @@ func (i *Indexer) handleEventOutputDns( return err } slog.Info( - fmt.Sprintf( - "found updated registration for domain: %s", - domainName, - ), + "found updated registration for domain: " + domainName, ) } return nil