Skip to content

Commit ad9c694

Browse files
committed
fix: use errors, strconv, and string concatenation to avoid fmt
Signed-off-by: Chris Gianelloni <[email protected]>
1 parent 276b315 commit ad9c694

File tree

3 files changed

+9
-15
lines changed

3 files changed

+9
-15
lines changed

cmd/cdnsd/main.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,7 @@ func main() {
113113
cfg.Metrics.ListenPort,
114114
)
115115
slog.Info(
116-
fmt.Sprintf(
117-
"starting listener for prometheus metrics connections on %s",
118-
metricsListenAddr,
119-
),
116+
"starting listener for prometheus metrics connections on " + metricsListenAddr,
120117
)
121118
metricsMux := http.NewServeMux()
122119
metricsMux.Handle("/metrics", promhttp.Handler())

internal/dns/dns.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ package dns
88

99
import (
1010
"crypto/rand"
11+
"errors"
1112
"fmt"
1213
"log/slog"
1314
"math/big"
1415
"net"
1516
"os"
17+
"strconv"
1618
"strings"
1719

1820
"github.com/blinklabs-io/cdnsd/internal/config"
@@ -38,10 +40,7 @@ func Start() error {
3840
cfg.Dns.ListenPort,
3941
)
4042
slog.Info(
41-
fmt.Sprintf(
42-
"starting DNS listener on %s",
43-
listenAddr,
44-
),
43+
"starting DNS listener on " + listenAddr,
4544
)
4645
// Setup handler
4746
dns.HandleFunc(".", handleQuery)
@@ -289,7 +288,7 @@ func handleQuery(w dns.ResponseWriter, r *dns.Msg) {
289288
func stateRecordToDnsRR(record state.DomainRecord) (dns.RR, error) {
290289
tmpTtl := ""
291290
if record.Ttl > 0 {
292-
tmpTtl = fmt.Sprintf("%d", record.Ttl)
291+
tmpTtl = strconv.Itoa(record.Ttl)
293292
}
294293
tmpRR := fmt.Sprintf(
295294
"%s %s IN %s %s",
@@ -358,7 +357,7 @@ func doQuery(msg *dns.Msg, address string, recursive bool) (*dns.Msg, error) {
358357
return nil, err
359358
}
360359
if resp == nil {
361-
return nil, fmt.Errorf("dns response empty")
360+
return nil, errors.New("dns response empty")
362361
}
363362
slog.Debug(
364363
fmt.Sprintf(

internal/indexer/indexer.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package indexer
88

99
import (
1010
"encoding/hex"
11+
"errors"
1112
"fmt"
1213
"log/slog"
1314
"math"
@@ -371,7 +372,7 @@ func (i *Indexer) handleEventOutputDns(
371372
}
372373
if record.Ttl.HasValue() {
373374
if record.Ttl.Value > math.MaxInt {
374-
return fmt.Errorf("record ttl value out of bounds")
375+
return errors.New("record ttl value out of bounds")
375376
}
376377
tmpRecord.Ttl = int(record.Ttl.Value) // #nosec G115
377378
}
@@ -381,10 +382,7 @@ func (i *Indexer) handleEventOutputDns(
381382
return err
382383
}
383384
slog.Info(
384-
fmt.Sprintf(
385-
"found updated registration for domain: %s",
386-
domainName,
387-
),
385+
"found updated registration for domain: " + domainName,
388386
)
389387
}
390388
return nil

0 commit comments

Comments
 (0)