From 98cf5872e97204f50dbf00938bc737394b6b11f8 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Tue, 21 Oct 2025 19:50:59 +0200 Subject: [PATCH] chore: linter: perfsprint Signed-off-by: Jakob Borg --- cmd/infra/stcrashreceiver/util.go | 4 ++-- cmd/strelaysrv/main.go | 5 +++-- lib/discover/global.go | 2 +- lib/httpcache/httpcache.go | 5 +++-- lib/ignore/ignore.go | 3 ++- lib/osutil/traversessymlink.go | 5 ++--- lib/pmp/pmp.go | 3 +-- lib/signature/signature.go | 4 ++-- lib/upnp/upnp.go | 2 +- 9 files changed, 17 insertions(+), 16 deletions(-) diff --git a/cmd/infra/stcrashreceiver/util.go b/cmd/infra/stcrashreceiver/util.go index 4e00d6fb6..ad58b5caa 100644 --- a/cmd/infra/stcrashreceiver/util.go +++ b/cmd/infra/stcrashreceiver/util.go @@ -10,7 +10,7 @@ import ( "bytes" "compress/gzip" "crypto/sha256" - "fmt" + "encoding/hex" "net" "net/http" "os" @@ -32,7 +32,7 @@ func userIDFor(req *http.Request) string { now := time.Now().Format("200601") salt := "stcrashreporter" hash := sha256.Sum256([]byte(salt + addr + now)) - return fmt.Sprintf("%x", hash[:8]) + return hex.EncodeToString(hash[:8]) } // 01234567890abcdef... => 01/23 diff --git a/cmd/strelaysrv/main.go b/cmd/strelaysrv/main.go index dca94b703..6f3247501 100644 --- a/cmd/strelaysrv/main.go +++ b/cmd/strelaysrv/main.go @@ -14,6 +14,7 @@ import ( "os" "os/signal" "path/filepath" + "strconv" "strings" "sync/atomic" "syscall" @@ -247,10 +248,10 @@ func main() { query.Set("pingInterval", pingInterval.String()) query.Set("networkTimeout", networkTimeout.String()) if sessionLimitBps > 0 { - query.Set("sessionLimitBps", fmt.Sprint(sessionLimitBps)) + query.Set("sessionLimitBps", strconv.Itoa(sessionLimitBps)) } if globalLimitBps > 0 { - query.Set("globalLimitBps", fmt.Sprint(globalLimitBps)) + query.Set("globalLimitBps", strconv.Itoa(globalLimitBps)) } if statusAddr != "" { query.Set("statusAddr", statusAddr) diff --git a/lib/discover/global.go b/lib/discover/global.go index d24b11717..008b86845 100644 --- a/lib/discover/global.go +++ b/lib/discover/global.go @@ -472,7 +472,7 @@ func ipv4Identity(port int) string { } func ipv6Identity(addr string) string { - return fmt.Sprintf("IPv6 local multicast discovery on address %s", addr) + return "IPv6 local multicast discovery on address " + addr } func http2EnabledTransport(t *http.Transport) *http.Transport { diff --git a/lib/httpcache/httpcache.go b/lib/httpcache/httpcache.go index e8e442dc1..41002c52c 100644 --- a/lib/httpcache/httpcache.go +++ b/lib/httpcache/httpcache.go @@ -12,6 +12,7 @@ import ( "context" "fmt" "net/http" + "strconv" "strings" "sync" "time" @@ -50,13 +51,13 @@ func (resp *recordedResponse) ServeHTTP(w http.ResponseWriter, r *http.Request) if strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") { w.Header().Set("Content-Encoding", "gzip") - w.Header().Set("Content-Length", fmt.Sprint(len(resp.gzip))) + w.Header().Set("Content-Length", strconv.Itoa(len(resp.gzip))) w.WriteHeader(resp.status) _, _ = w.Write(resp.gzip) return } - w.Header().Set("Content-Length", fmt.Sprint(len(resp.data))) + w.Header().Set("Content-Length", strconv.Itoa(len(resp.data))) w.WriteHeader(resp.status) _, _ = w.Write(resp.data) } diff --git a/lib/ignore/ignore.go b/lib/ignore/ignore.go index 062153bfd..2acf7c2e2 100644 --- a/lib/ignore/ignore.go +++ b/lib/ignore/ignore.go @@ -10,6 +10,7 @@ import ( "bufio" "bytes" "crypto/sha256" + "encoding/hex" "errors" "fmt" "io" @@ -353,7 +354,7 @@ func hashPatterns(patterns []Pattern) string { h.Write([]byte(pat.String())) h.Write([]byte("\n")) } - return fmt.Sprintf("%x", h.Sum(nil)) + return hex.EncodeToString(h.Sum(nil)) } func loadIgnoreFile(fs fs.Filesystem, file string) (fs.File, fs.FileInfo, error) { diff --git a/lib/osutil/traversessymlink.go b/lib/osutil/traversessymlink.go index bcb1d3577..4078febbd 100644 --- a/lib/osutil/traversessymlink.go +++ b/lib/osutil/traversessymlink.go @@ -7,7 +7,6 @@ package osutil import ( - "fmt" "path/filepath" "github.com/syncthing/syncthing/lib/fs" @@ -19,7 +18,7 @@ type TraversesSymlinkError struct { } func (e *TraversesSymlinkError) Error() string { - return fmt.Sprintf("traverses symlink: %s", e.path) + return "traverses symlink: " + e.path } // NotADirectoryError is an error indicating an expected path is not a directory @@ -28,7 +27,7 @@ type NotADirectoryError struct { } func (e *NotADirectoryError) Error() string { - return fmt.Sprintf("not a directory: %s", e.path) + return "not a directory: " + e.path } // TraversesSymlink returns an error if any path component of name (including name diff --git a/lib/pmp/pmp.go b/lib/pmp/pmp.go index feee6972d..3b7ad8d46 100644 --- a/lib/pmp/pmp.go +++ b/lib/pmp/pmp.go @@ -9,7 +9,6 @@ package pmp import ( "context" "errors" - "fmt" "log/slog" "net" "strings" @@ -90,7 +89,7 @@ type wrapper struct { } func (w *wrapper) ID() string { - return fmt.Sprintf("NAT-PMP@%s", w.gatewayIP.String()) + return "NAT-PMP@" + w.gatewayIP.String() } func (w *wrapper) GetLocalIPv4Address() net.IP { diff --git a/lib/signature/signature.go b/lib/signature/signature.go index de5c025ee..67cca0995 100644 --- a/lib/signature/signature.go +++ b/lib/signature/signature.go @@ -14,9 +14,9 @@ import ( "crypto/sha256" "crypto/x509" "encoding/asn1" + "encoding/hex" "encoding/pem" "errors" - "fmt" "io" "math/big" @@ -135,7 +135,7 @@ func hashReader(r io.Reader) ([]byte, error) { if _, err := io.Copy(h, r); err != nil { return nil, err } - hash := []byte(fmt.Sprintf("%x", h.Sum(nil))) + hash := []byte(hex.EncodeToString(h.Sum(nil))) return hash, nil } diff --git a/lib/upnp/upnp.go b/lib/upnp/upnp.go index 6a0235ec4..9f49d8214 100644 --- a/lib/upnp/upnp.go +++ b/lib/upnp/upnp.go @@ -86,7 +86,7 @@ type UnsupportedDeviceTypeError struct { } func (e *UnsupportedDeviceTypeError) Error() string { - return fmt.Sprintf("Unsupported UPnP device of type %s", e.deviceType) + return "unsupported UPnP device of type " + e.deviceType } const (