chore: go fix

Signed-off-by: Deluan <deluan@navidrome.org>
This commit is contained in:
Deluan
2026-05-28 22:09:54 -03:00
parent 59b6755014
commit 2a43c4683e
15 changed files with 34 additions and 36 deletions
+3 -3
View File
@@ -32,17 +32,17 @@ var inspectCmd = &cobra.Command{
},
}
var marshalers = map[string]func(interface{}) ([]byte, error){
var marshalers = map[string]func(any) ([]byte, error){
"pretty": prettyMarshal,
"toml": toml.Marshal,
"yaml": yaml.Marshal,
"json": json.Marshal,
"jsonindent": func(v interface{}) ([]byte, error) {
"jsonindent": func(v any) ([]byte, error) {
return json.MarshalIndent(v, "", " ")
},
}
func prettyMarshal(v interface{}) ([]byte, error) {
func prettyMarshal(v any) ([]byte, error) {
out := v.([]core.InspectOutput)
var res strings.Builder
for i := range out {
+1 -1
View File
@@ -169,7 +169,7 @@ func BenchmarkArtworkGetE2EConcurrent(b *testing.B) {
for i := 0; i < b.N; i++ {
var wg sync.WaitGroup
wg.Add(n)
for g := 0; g < n; g++ {
for range n {
go func() {
defer wg.Done()
r, _, err := aw.Get(context.Background(), artID, 300, true)
+2 -2
View File
@@ -35,8 +35,8 @@ func generatePNG(t testing.TB, width, height int) []byte {
// generateGradientImage creates an RGBA image with a diagonal gradient pattern.
func generateGradientImage(width, height int) *image.RGBA {
img := image.NewRGBA(image.Rect(0, 0, width, height))
for y := 0; y < height; y++ {
for x := 0; x < width; x++ {
for y := range height {
for x := range width {
r := uint8((x * 255) / width)
g := uint8((y * 255) / height)
b := uint8(((x + y) * 255) / (width + height))
+2 -2
View File
@@ -496,8 +496,8 @@ func createFFmpegCommand(cmd, path string, maxBitRate, offset int) []string {
// Pre-input seeking: ffmpeg seeks at the demuxer level (fast)
// instead of decoding all frames up to the offset (slow).
insertAt := len(args)
for i := len(args) - 1; i >= 0; i-- {
if args[i] == "-i" {
for i, arg := range slices.Backward(args) {
if arg == "-i" {
insertAt = i
break
}
+1 -1
View File
@@ -98,7 +98,7 @@ func (r *shareRepositoryWrapper) Save(entity any) (string, error) {
s.ExpiresAt = new(time.Now().Add(conf.Server.DefaultShareExpiration))
}
firstId := strings.SplitN(s.ResourceIDs, ",", 2)[0]
firstId, _, _ := strings.Cut(s.ResourceIDs, ",")
v, err := model.GetEntityByID(r.ctx, r.ds, firstId)
if err != nil {
return "", err
+1 -1
View File
@@ -36,6 +36,6 @@ func (f *journalFormatter) Format(entry *logrus.Entry) ([]byte, error) {
if !ok {
priority = 6 // default to info for unknown levels
}
prefix := []byte(fmt.Sprintf("<%d>", priority))
prefix := fmt.Appendf(nil, "<%d>", priority)
return append(prefix, formatted...), nil
}
+2 -2
View File
@@ -47,8 +47,8 @@ func (c TagConf) SplitTagValue(values []string) []string {
tag = c.SplitRx.ReplaceAllString(tag, consts.Zwsp)
// Split by the zero-width space and trim each substring.
parts := strings.Split(tag, consts.Zwsp)
for _, part := range parts {
parts := strings.SplitSeq(tag, consts.Zwsp)
for part := range parts {
result = append(result, strings.TrimSpace(part))
}
}
+6 -6
View File
@@ -66,7 +66,7 @@ func normalizeForFTS(values ...string) string {
result = append(result, variant)
}
for _, v := range values {
for _, word := range strings.Fields(v) {
for word := range strings.FieldsSeq(v) {
transliterated := sanitize.Accents(word)
// Concatenated ASCII form: R.E.M. → REM, AC/DC → ACDC, St-Étienne → StEtienne.
add(word, fts5PunctStrip.ReplaceAllString(transliterated, ""))
@@ -279,9 +279,9 @@ type ftsSearch struct {
}
// ToSql returns a single-query fallback for the REST filter path (no two-phase split).
func (s *ftsSearch) ToSql() (string, []interface{}, error) {
func (s *ftsSearch) ToSql() (string, []any, error) {
sql := s.tableName + ".rowid IN (SELECT rowid FROM " + s.ftsTable + " WHERE " + s.ftsTable + " MATCH ?)"
return sql, []interface{}{s.matchExpr}, nil
return sql, []any{s.matchExpr}, nil
}
// execute runs a two-phase FTS5 search:
@@ -373,8 +373,8 @@ func ftsQueryDegraded(original, ftsQuery string) bool {
// Check if all effective FTS tokens are very short (≤2 chars).
// Short tokens with prefix matching are too broad when special chars were stripped.
// For quoted phrases, extract the content and check the tokens inside.
tokens := strings.Fields(ftsQuery)
for _, t := range tokens {
tokens := strings.FieldsSeq(ftsQuery)
for t := range tokens {
t = strings.TrimSuffix(t, "*")
// Skip internal phrase placeholders
if strings.HasPrefix(t, "\x00") {
@@ -390,7 +390,7 @@ func ftsQueryDegraded(original, ftsQuery string) bool {
// Extract content between quotes
inner := strings.Trim(t, `"`)
innerAlpha := fts5PunctStrip.ReplaceAllString(inner, " ")
for _, it := range strings.Fields(innerAlpha) {
for it := range strings.FieldsSeq(innerAlpha) {
if len(it) > 2 {
return false
}
+1 -1
View File
@@ -16,7 +16,7 @@ type likeSearch struct {
filter Sqlizer
}
func (s *likeSearch) ToSql() (string, []interface{}, error) {
func (s *likeSearch) ToSql() (string, []any, error) {
return s.filter.ToSql()
}
+2 -3
View File
@@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"io"
"maps"
"os"
"path/filepath"
"sync"
@@ -540,9 +541,7 @@ func (s *taskQueueServiceImpl) cleanupLoop() {
func (s *taskQueueServiceImpl) runCleanup() {
s.mu.Lock()
queues := make(map[string]*queueState, len(s.queues))
for k, v := range s.queues {
queues[k] = v
}
maps.Copy(queues, s.queues)
s.mu.Unlock()
now := time.Now().UnixMilli()
+7 -7
View File
@@ -367,8 +367,8 @@ var _ = Describe("TaskQueueService", func() {
// Enqueue several more tasks — they stay pending since the worker is busy
var pendingIDs []string
for i := 0; i < 3; i++ {
taskID, err := service.Enqueue(ctx, "clear-test", []byte(fmt.Sprintf("task-%d", i)))
for i := range 3 {
taskID, err := service.Enqueue(ctx, "clear-test", fmt.Appendf(nil, "task-%d", i))
Expect(err).ToNot(HaveOccurred())
pendingIDs = append(pendingIDs, taskID)
}
@@ -674,8 +674,8 @@ var _ = Describe("TaskQueueService", func() {
Expect(err).ToNot(HaveOccurred())
// Enqueue 5 tasks
for i := 0; i < 5; i++ {
_, err := service.Enqueue(ctx, "delay-concurrent", []byte(fmt.Sprintf("task-%d", i)))
for i := range 5 {
_, err := service.Enqueue(ctx, "delay-concurrent", fmt.Appendf(nil, "task-%d", i))
Expect(err).ToNot(HaveOccurred())
}
@@ -1112,7 +1112,7 @@ var _ = Describe("TaskQueueService Integration", Ordered, func() {
// the second will be dequeued but block on the rate limiter (status=running),
// the rest will stay pending.
var taskIDs []string
for i := 0; i < 5; i++ {
for range 5 {
output, err := callTestTaskQueue(ctx, testTaskQueueInput{
Operation: "enqueue",
QueueName: "test-cancel",
@@ -1186,11 +1186,11 @@ var _ = Describe("TaskQueueService Integration", Ordered, func() {
Expect(err).ToNot(HaveOccurred())
// Enqueue several tasks
for i := 0; i < 4; i++ {
for i := range 4 {
_, err := callTestTaskQueue(ctx, testTaskQueueInput{
Operation: "enqueue",
QueueName: "test-clear",
Payload: []byte(fmt.Sprintf("task-%d", i)),
Payload: fmt.Appendf(nil, "task-%d", i),
})
Expect(err).ToNot(HaveOccurred())
}
+1 -1
View File
@@ -185,7 +185,7 @@ var _ = Describe("ParseCrontab", func() {
// findSetBit returns the lowest bit position set in v, ignoring the starBit (bit 63).
func findSetBit(v uint64) int {
v &^= 1 << 63 // clear starBit
for i := 0; i < 63; i++ {
for i := range 63 {
if v&(1<<uint(i)) != 0 {
return i
}
+1 -1
View File
@@ -1,6 +1,7 @@
package subsonic
import (
"context"
"encoding/json"
"encoding/xml"
"fmt"
@@ -13,7 +14,6 @@ import (
"github.com/navidrome/navidrome/server/subsonic/responses"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"golang.org/x/net/context"
)
var _ = Describe("sendResponse", func() {
+2 -3
View File
@@ -4,6 +4,7 @@ import (
"bytes"
"context"
"errors"
"maps"
"net/http"
"sync"
"time"
@@ -76,9 +77,7 @@ func (t *requestThrottle) handler(next http.Handler) http.Handler {
next.ServeHTTP(buf, r)
}()
for k, v := range buf.header {
w.Header()[k] = v
}
maps.Copy(w.Header(), buf.header)
if buf.code > 0 {
w.WriteHeader(buf.code)
}
+2 -2
View File
@@ -116,7 +116,7 @@ func BenchmarkConcurrentCacheRead(b *testing.B) {
for i := 0; i < b.N; i++ {
var wg sync.WaitGroup
wg.Add(n)
for g := 0; g < n; g++ {
for range n {
go func() {
defer wg.Done()
s, err := fc.Get(context.Background(), item)
@@ -152,7 +152,7 @@ func BenchmarkConcurrentCacheMiss(b *testing.B) {
wg.Add(n)
// All goroutines request the SAME key (not yet cached)
item := &benchItem{key: fmt.Sprintf("miss-%d", i)}
for g := 0; g < n; g++ {
for range n {
go func() {
defer wg.Done()
s, err := fc.Get(context.Background(), item)