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

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, "pretty": prettyMarshal,
"toml": toml.Marshal, "toml": toml.Marshal,
"yaml": yaml.Marshal, "yaml": yaml.Marshal,
"json": json.Marshal, "json": json.Marshal,
"jsonindent": func(v interface{}) ([]byte, error) { "jsonindent": func(v any) ([]byte, error) {
return json.MarshalIndent(v, "", " ") return json.MarshalIndent(v, "", " ")
}, },
} }
func prettyMarshal(v interface{}) ([]byte, error) { func prettyMarshal(v any) ([]byte, error) {
out := v.([]core.InspectOutput) out := v.([]core.InspectOutput)
var res strings.Builder var res strings.Builder
for i := range out { for i := range out {

View file

@ -169,7 +169,7 @@ func BenchmarkArtworkGetE2EConcurrent(b *testing.B) {
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
var wg sync.WaitGroup var wg sync.WaitGroup
wg.Add(n) wg.Add(n)
for g := 0; g < n; g++ { for range n {
go func() { go func() {
defer wg.Done() defer wg.Done()
r, _, err := aw.Get(context.Background(), artID, 300, true) r, _, err := aw.Get(context.Background(), artID, 300, true)

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. // generateGradientImage creates an RGBA image with a diagonal gradient pattern.
func generateGradientImage(width, height int) *image.RGBA { func generateGradientImage(width, height int) *image.RGBA {
img := image.NewRGBA(image.Rect(0, 0, width, height)) img := image.NewRGBA(image.Rect(0, 0, width, height))
for y := 0; y < height; y++ { for y := range height {
for x := 0; x < width; x++ { for x := range width {
r := uint8((x * 255) / width) r := uint8((x * 255) / width)
g := uint8((y * 255) / height) g := uint8((y * 255) / height)
b := uint8(((x + y) * 255) / (width + height)) b := uint8(((x + y) * 255) / (width + height))

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) // Pre-input seeking: ffmpeg seeks at the demuxer level (fast)
// instead of decoding all frames up to the offset (slow). // instead of decoding all frames up to the offset (slow).
insertAt := len(args) insertAt := len(args)
for i := len(args) - 1; i >= 0; i-- { for i, arg := range slices.Backward(args) {
if args[i] == "-i" { if arg == "-i" {
insertAt = i insertAt = i
break break
} }

View file

@ -98,7 +98,7 @@ func (r *shareRepositoryWrapper) Save(entity any) (string, error) {
s.ExpiresAt = new(time.Now().Add(conf.Server.DefaultShareExpiration)) 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) v, err := model.GetEntityByID(r.ctx, r.ds, firstId)
if err != nil { if err != nil {
return "", err return "", err

View file

@ -36,6 +36,6 @@ func (f *journalFormatter) Format(entry *logrus.Entry) ([]byte, error) {
if !ok { if !ok {
priority = 6 // default to info for unknown levels 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 return append(prefix, formatted...), nil
} }

View file

@ -47,8 +47,8 @@ func (c TagConf) SplitTagValue(values []string) []string {
tag = c.SplitRx.ReplaceAllString(tag, consts.Zwsp) tag = c.SplitRx.ReplaceAllString(tag, consts.Zwsp)
// Split by the zero-width space and trim each substring. // Split by the zero-width space and trim each substring.
parts := strings.Split(tag, consts.Zwsp) parts := strings.SplitSeq(tag, consts.Zwsp)
for _, part := range parts { for part := range parts {
result = append(result, strings.TrimSpace(part)) result = append(result, strings.TrimSpace(part))
} }
} }

View file

@ -66,7 +66,7 @@ func normalizeForFTS(values ...string) string {
result = append(result, variant) result = append(result, variant)
} }
for _, v := range values { for _, v := range values {
for _, word := range strings.Fields(v) { for word := range strings.FieldsSeq(v) {
transliterated := sanitize.Accents(word) transliterated := sanitize.Accents(word)
// Concatenated ASCII form: R.E.M. → REM, AC/DC → ACDC, St-Étienne → StEtienne. // Concatenated ASCII form: R.E.M. → REM, AC/DC → ACDC, St-Étienne → StEtienne.
add(word, fts5PunctStrip.ReplaceAllString(transliterated, "")) 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). // 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 ?)" 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: // 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). // Check if all effective FTS tokens are very short (≤2 chars).
// Short tokens with prefix matching are too broad when special chars were stripped. // Short tokens with prefix matching are too broad when special chars were stripped.
// For quoted phrases, extract the content and check the tokens inside. // For quoted phrases, extract the content and check the tokens inside.
tokens := strings.Fields(ftsQuery) tokens := strings.FieldsSeq(ftsQuery)
for _, t := range tokens { for t := range tokens {
t = strings.TrimSuffix(t, "*") t = strings.TrimSuffix(t, "*")
// Skip internal phrase placeholders // Skip internal phrase placeholders
if strings.HasPrefix(t, "\x00") { if strings.HasPrefix(t, "\x00") {
@ -390,7 +390,7 @@ func ftsQueryDegraded(original, ftsQuery string) bool {
// Extract content between quotes // Extract content between quotes
inner := strings.Trim(t, `"`) inner := strings.Trim(t, `"`)
innerAlpha := fts5PunctStrip.ReplaceAllString(inner, " ") innerAlpha := fts5PunctStrip.ReplaceAllString(inner, " ")
for _, it := range strings.Fields(innerAlpha) { for it := range strings.FieldsSeq(innerAlpha) {
if len(it) > 2 { if len(it) > 2 {
return false return false
} }

View file

@ -16,7 +16,7 @@ type likeSearch struct {
filter Sqlizer filter Sqlizer
} }
func (s *likeSearch) ToSql() (string, []interface{}, error) { func (s *likeSearch) ToSql() (string, []any, error) {
return s.filter.ToSql() return s.filter.ToSql()
} }

View file

@ -6,6 +6,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"maps"
"os" "os"
"path/filepath" "path/filepath"
"sync" "sync"
@ -540,9 +541,7 @@ func (s *taskQueueServiceImpl) cleanupLoop() {
func (s *taskQueueServiceImpl) runCleanup() { func (s *taskQueueServiceImpl) runCleanup() {
s.mu.Lock() s.mu.Lock()
queues := make(map[string]*queueState, len(s.queues)) queues := make(map[string]*queueState, len(s.queues))
for k, v := range s.queues { maps.Copy(queues, s.queues)
queues[k] = v
}
s.mu.Unlock() s.mu.Unlock()
now := time.Now().UnixMilli() now := time.Now().UnixMilli()

View file

@ -367,8 +367,8 @@ var _ = Describe("TaskQueueService", func() {
// Enqueue several more tasks — they stay pending since the worker is busy // Enqueue several more tasks — they stay pending since the worker is busy
var pendingIDs []string var pendingIDs []string
for i := 0; i < 3; i++ { for i := range 3 {
taskID, err := service.Enqueue(ctx, "clear-test", []byte(fmt.Sprintf("task-%d", i))) taskID, err := service.Enqueue(ctx, "clear-test", fmt.Appendf(nil, "task-%d", i))
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
pendingIDs = append(pendingIDs, taskID) pendingIDs = append(pendingIDs, taskID)
} }
@ -674,8 +674,8 @@ var _ = Describe("TaskQueueService", func() {
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
// Enqueue 5 tasks // Enqueue 5 tasks
for i := 0; i < 5; i++ { for i := range 5 {
_, err := service.Enqueue(ctx, "delay-concurrent", []byte(fmt.Sprintf("task-%d", i))) _, err := service.Enqueue(ctx, "delay-concurrent", fmt.Appendf(nil, "task-%d", i))
Expect(err).ToNot(HaveOccurred()) 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 second will be dequeued but block on the rate limiter (status=running),
// the rest will stay pending. // the rest will stay pending.
var taskIDs []string var taskIDs []string
for i := 0; i < 5; i++ { for range 5 {
output, err := callTestTaskQueue(ctx, testTaskQueueInput{ output, err := callTestTaskQueue(ctx, testTaskQueueInput{
Operation: "enqueue", Operation: "enqueue",
QueueName: "test-cancel", QueueName: "test-cancel",
@ -1186,11 +1186,11 @@ var _ = Describe("TaskQueueService Integration", Ordered, func() {
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
// Enqueue several tasks // Enqueue several tasks
for i := 0; i < 4; i++ { for i := range 4 {
_, err := callTestTaskQueue(ctx, testTaskQueueInput{ _, err := callTestTaskQueue(ctx, testTaskQueueInput{
Operation: "enqueue", Operation: "enqueue",
QueueName: "test-clear", QueueName: "test-clear",
Payload: []byte(fmt.Sprintf("task-%d", i)), Payload: fmt.Appendf(nil, "task-%d", i),
}) })
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
} }

View file

@ -185,7 +185,7 @@ var _ = Describe("ParseCrontab", func() {
// findSetBit returns the lowest bit position set in v, ignoring the starBit (bit 63). // findSetBit returns the lowest bit position set in v, ignoring the starBit (bit 63).
func findSetBit(v uint64) int { func findSetBit(v uint64) int {
v &^= 1 << 63 // clear starBit v &^= 1 << 63 // clear starBit
for i := 0; i < 63; i++ { for i := range 63 {
if v&(1<<uint(i)) != 0 { if v&(1<<uint(i)) != 0 {
return i return i
} }

View file

@ -1,6 +1,7 @@
package subsonic package subsonic
import ( import (
"context"
"encoding/json" "encoding/json"
"encoding/xml" "encoding/xml"
"fmt" "fmt"
@ -13,7 +14,6 @@ import (
"github.com/navidrome/navidrome/server/subsonic/responses" "github.com/navidrome/navidrome/server/subsonic/responses"
. "github.com/onsi/ginkgo/v2" . "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
"golang.org/x/net/context"
) )
var _ = Describe("sendResponse", func() { var _ = Describe("sendResponse", func() {

View file

@ -4,6 +4,7 @@ import (
"bytes" "bytes"
"context" "context"
"errors" "errors"
"maps"
"net/http" "net/http"
"sync" "sync"
"time" "time"
@ -76,9 +77,7 @@ func (t *requestThrottle) handler(next http.Handler) http.Handler {
next.ServeHTTP(buf, r) next.ServeHTTP(buf, r)
}() }()
for k, v := range buf.header { maps.Copy(w.Header(), buf.header)
w.Header()[k] = v
}
if buf.code > 0 { if buf.code > 0 {
w.WriteHeader(buf.code) w.WriteHeader(buf.code)
} }

View file

@ -116,7 +116,7 @@ func BenchmarkConcurrentCacheRead(b *testing.B) {
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
var wg sync.WaitGroup var wg sync.WaitGroup
wg.Add(n) wg.Add(n)
for g := 0; g < n; g++ { for range n {
go func() { go func() {
defer wg.Done() defer wg.Done()
s, err := fc.Get(context.Background(), item) s, err := fc.Get(context.Background(), item)
@ -152,7 +152,7 @@ func BenchmarkConcurrentCacheMiss(b *testing.B) {
wg.Add(n) wg.Add(n)
// All goroutines request the SAME key (not yet cached) // All goroutines request the SAME key (not yet cached)
item := &benchItem{key: fmt.Sprintf("miss-%d", i)} item := &benchItem{key: fmt.Sprintf("miss-%d", i)}
for g := 0; g < n; g++ { for range n {
go func() { go func() {
defer wg.Done() defer wg.Done()
s, err := fc.Get(context.Background(), item) s, err := fc.Get(context.Background(), item)