fix: apply go fix updates (any, range loop, slices, maps)

This commit is contained in:
2026-06-16 13:36:45 +02:00
committed by Milas Holsting
parent 8f0549b290
commit bc7a3f58cf
6 changed files with 17 additions and 19 deletions

View File

@@ -239,7 +239,7 @@ func (a Anime) DurationSeconds() float64 {
var currentValue int
hasValue := false
for _, token := range strings.Fields(strings.ToLower(a.Duration)) {
for token := range strings.FieldsSeq(strings.ToLower(a.Duration)) {
value, err := strconv.Atoi(token)
if err == nil {
currentValue = value

View File

@@ -206,7 +206,7 @@ func (e engine) scoreRankedCandidates(
var g errgroup.Group
g.SetLimit(6)
for i := 0; i < limit; i++ {
for i := range limit {
item := ranked[i]
g.Go(func() error {
anime := item.anime

View File

@@ -5,6 +5,7 @@ import (
"mal/integrations/jikan"
"mal/internal/db"
"mal/internal/domain"
"slices"
"testing"
"time"
)
@@ -219,10 +220,8 @@ func animeIDs(animes []domain.Anime) []int {
func hasGenreSearchQuery(queries []profileSearchQuery, genreID int) bool {
for _, query := range queries {
for _, id := range query.genreIDs {
if id == genreID {
return true
}
if slices.Contains(query.genreIDs, genreID) {
return true
}
}
return false

View File

@@ -176,5 +176,5 @@ func commandPaletteLimit(limit int64) int64 {
}
type scanner interface {
Scan(dest ...interface{}) error
Scan(dest ...any) error
}

View File

@@ -8,24 +8,24 @@ import (
type instrumentedDB struct {
db interface {
ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
ExecContext(context.Context, string, ...any) (sql.Result, error)
PrepareContext(context.Context, string) (*sql.Stmt, error)
QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
QueryRowContext(context.Context, string, ...interface{}) *sql.Row
QueryContext(context.Context, string, ...any) (*sql.Rows, error)
QueryRowContext(context.Context, string, ...any) *sql.Row
}
metrics *Metrics
}
func InstrumentDB(db interface {
ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
ExecContext(context.Context, string, ...any) (sql.Result, error)
PrepareContext(context.Context, string) (*sql.Stmt, error)
QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
QueryRowContext(context.Context, string, ...interface{}) *sql.Row
QueryContext(context.Context, string, ...any) (*sql.Rows, error)
QueryRowContext(context.Context, string, ...any) *sql.Row
}, metrics *Metrics) *instrumentedDB {
return &instrumentedDB{db: db, metrics: metrics}
}
func (db *instrumentedDB) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error) {
func (db *instrumentedDB) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error) {
start := time.Now()
result, err := db.db.ExecContext(ctx, query, args...)
db.metrics.ObserveDBQuery("exec", time.Since(start), err)
@@ -36,14 +36,14 @@ func (db *instrumentedDB) PrepareContext(ctx context.Context, query string) (*sq
return db.db.PrepareContext(ctx, query)
}
func (db *instrumentedDB) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error) {
func (db *instrumentedDB) QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error) {
start := time.Now()
rows, err := db.db.QueryContext(ctx, query, args...)
db.metrics.ObserveDBQuery("query", time.Since(start), err)
return rows, err
}
func (db *instrumentedDB) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row {
func (db *instrumentedDB) QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row {
start := time.Now()
row := db.db.QueryRowContext(ctx, query, args...)
db.metrics.ObserveDBQuery("query_row", time.Since(start), nil)

View File

@@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"log"
"maps"
"net"
"os"
"path/filepath"
@@ -294,9 +295,7 @@ func cloneFields(fields map[string]any) map[string]any {
}
copyFields := make(map[string]any, len(fields))
for key, value := range fields {
copyFields[key] = value
}
maps.Copy(copyFields, fields)
return copyFields
}