perfsprint 18→0:strconv.Itoa/FormatInt/FormatUint/FormatBool 替代 fmt.Sprintf、无动词 fmt.Errorf→errors.New、纯字符串拼接。全部语义等价(已核对 diff)。修正 fixer 遗留的 import 问题(引入 goimports 统一整理)。

Result: {"status":"keep","total_issues":56,"golint_canonicalheader":8,"golint_errname":1,"golint_errorlint":12,"golint_forcetypeassert":3,"golint_gosec":0,"golint_intrange":3,"golint_modernize":5,"golint_nilnil":3,"golint_perfsprint":0,"golint_prealloc":3,"golint_recvcheck":7,"golint_usestdlibvars":3,"golint_wastedassign":7,"golint_total":55,"eslint_problems":1,"eslint_errors":0,"eslint_warnings":1,"tsc_errors":0,"measure_s":47}
This commit is contained in:
ryan
2026-08-16 17:34:44 +08:00
parent b76f707c8b
commit 699e95f12c
54 changed files with 188 additions and 157 deletions
+4 -3
View File
@@ -5,6 +5,7 @@ package objectstore
import (
"context"
"errors"
"fmt"
"io"
"mime"
@@ -20,7 +21,7 @@ type localBackend struct {
func newLocalBackend(cfg LocalConfig) (*localBackend, error) {
root := filepath.Clean(cfg.Root)
if root == "" {
return nil, fmt.Errorf("local root is required")
return nil, errors.New("local root is required")
}
return &localBackend{root: root}, nil
}
@@ -103,7 +104,7 @@ func (b *localBackend) path(key string) (string, error) {
}
rel, err := filepath.Rel(absRoot, absPath)
if err != nil || strings.HasPrefix(rel, "..") {
return "", fmt.Errorf("storage key escapes local root")
return "", errors.New("storage key escapes local root")
}
return cleanPath, nil
}
@@ -114,7 +115,7 @@ func (b *localBackend) path(key string) (string, error) {
path := filepath.Join(b.root, cleanKey)
rel, err := filepath.Rel(b.root, path)
if err != nil || strings.HasPrefix(rel, "..") {
return "", fmt.Errorf("storage key escapes local root")
return "", errors.New("storage key escapes local root")
}
return path, nil
}
@@ -4,7 +4,7 @@
package batchwriter
import (
"fmt"
"errors"
"time"
)
@@ -51,19 +51,19 @@ func DefaultConfig() Config {
func (c Config) validate() error {
if c.QueueSize <= 0 {
return fmt.Errorf("batchwriter: queue size must be positive")
return errors.New("batchwriter: queue size must be positive")
}
if c.MaxBatchSize <= 0 {
return fmt.Errorf("batchwriter: max batch size must be positive")
return errors.New("batchwriter: max batch size must be positive")
}
if c.MinBatchSize < 0 {
return fmt.Errorf("batchwriter: min batch size must be non-negative")
return errors.New("batchwriter: min batch size must be non-negative")
}
if c.FlushInterval <= 0 {
return fmt.Errorf("batchwriter: flush interval must be positive")
return errors.New("batchwriter: flush interval must be positive")
}
if c.MaxFlushWait < 0 {
return fmt.Errorf("batchwriter: max flush wait must be non-negative")
return errors.New("batchwriter: max flush wait must be non-negative")
}
return nil
}
+2 -1
View File
@@ -9,6 +9,7 @@ import (
"encoding/json"
"fmt"
"log"
"strconv"
"strings"
"time"
@@ -83,7 +84,7 @@ func init() {
if err := redisotel.InstrumentTracing(
Redis,
redisotel.WithAttributes(
attribute.String("db.instance", fmt.Sprintf("%v", cfg.DB)),
attribute.String("db.instance", strconv.Itoa(cfg.DB)),
attribute.String("db.ip", strings.Join(cfg.Addrs, ",")),
attribute.String("db.system", "Redis"),
),