Skip to content

fix: use errors, strconv, and string concatenation to avoid fmt #301

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions cmd/cdnsd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
11 changes: 5 additions & 6 deletions internal/dns/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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(
Expand Down
8 changes: 3 additions & 5 deletions internal/indexer/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package indexer

import (
"encoding/hex"
"errors"
"fmt"
"log/slog"
"math"
Expand Down Expand Up @@ -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
}
Expand All @@ -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
Expand Down