fix: apply go fix updates (any, range loop, slices, maps)
This commit is contained in:
@@ -239,7 +239,7 @@ func (a Anime) DurationSeconds() float64 {
|
|||||||
var currentValue int
|
var currentValue int
|
||||||
hasValue := false
|
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)
|
value, err := strconv.Atoi(token)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
currentValue = value
|
currentValue = value
|
||||||
|
|||||||
@@ -206,7 +206,7 @@ func (e engine) scoreRankedCandidates(
|
|||||||
var g errgroup.Group
|
var g errgroup.Group
|
||||||
g.SetLimit(6)
|
g.SetLimit(6)
|
||||||
|
|
||||||
for i := 0; i < limit; i++ {
|
for i := range limit {
|
||||||
item := ranked[i]
|
item := ranked[i]
|
||||||
g.Go(func() error {
|
g.Go(func() error {
|
||||||
anime := item.anime
|
anime := item.anime
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"mal/integrations/jikan"
|
"mal/integrations/jikan"
|
||||||
"mal/internal/db"
|
"mal/internal/db"
|
||||||
"mal/internal/domain"
|
"mal/internal/domain"
|
||||||
|
"slices"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@@ -219,10 +220,8 @@ func animeIDs(animes []domain.Anime) []int {
|
|||||||
|
|
||||||
func hasGenreSearchQuery(queries []profileSearchQuery, genreID int) bool {
|
func hasGenreSearchQuery(queries []profileSearchQuery, genreID int) bool {
|
||||||
for _, query := range queries {
|
for _, query := range queries {
|
||||||
for _, id := range query.genreIDs {
|
if slices.Contains(query.genreIDs, genreID) {
|
||||||
if id == genreID {
|
return true
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -176,5 +176,5 @@ func commandPaletteLimit(limit int64) int64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type scanner interface {
|
type scanner interface {
|
||||||
Scan(dest ...interface{}) error
|
Scan(dest ...any) error
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,24 +8,24 @@ import (
|
|||||||
|
|
||||||
type instrumentedDB struct {
|
type instrumentedDB struct {
|
||||||
db interface {
|
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)
|
PrepareContext(context.Context, string) (*sql.Stmt, error)
|
||||||
QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
|
QueryContext(context.Context, string, ...any) (*sql.Rows, error)
|
||||||
QueryRowContext(context.Context, string, ...interface{}) *sql.Row
|
QueryRowContext(context.Context, string, ...any) *sql.Row
|
||||||
}
|
}
|
||||||
metrics *Metrics
|
metrics *Metrics
|
||||||
}
|
}
|
||||||
|
|
||||||
func InstrumentDB(db interface {
|
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)
|
PrepareContext(context.Context, string) (*sql.Stmt, error)
|
||||||
QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
|
QueryContext(context.Context, string, ...any) (*sql.Rows, error)
|
||||||
QueryRowContext(context.Context, string, ...interface{}) *sql.Row
|
QueryRowContext(context.Context, string, ...any) *sql.Row
|
||||||
}, metrics *Metrics) *instrumentedDB {
|
}, metrics *Metrics) *instrumentedDB {
|
||||||
return &instrumentedDB{db: db, metrics: metrics}
|
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()
|
start := time.Now()
|
||||||
result, err := db.db.ExecContext(ctx, query, args...)
|
result, err := db.db.ExecContext(ctx, query, args...)
|
||||||
db.metrics.ObserveDBQuery("exec", time.Since(start), err)
|
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)
|
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()
|
start := time.Now()
|
||||||
rows, err := db.db.QueryContext(ctx, query, args...)
|
rows, err := db.db.QueryContext(ctx, query, args...)
|
||||||
db.metrics.ObserveDBQuery("query", time.Since(start), err)
|
db.metrics.ObserveDBQuery("query", time.Since(start), err)
|
||||||
return rows, 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()
|
start := time.Now()
|
||||||
row := db.db.QueryRowContext(ctx, query, args...)
|
row := db.db.QueryRowContext(ctx, query, args...)
|
||||||
db.metrics.ObserveDBQuery("query_row", time.Since(start), nil)
|
db.metrics.ObserveDBQuery("query_row", time.Since(start), nil)
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"maps"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@@ -294,9 +295,7 @@ func cloneFields(fields map[string]any) map[string]any {
|
|||||||
}
|
}
|
||||||
|
|
||||||
copyFields := make(map[string]any, len(fields))
|
copyFields := make(map[string]any, len(fields))
|
||||||
for key, value := range fields {
|
maps.Copy(copyFields, fields)
|
||||||
copyFields[key] = value
|
|
||||||
}
|
|
||||||
|
|
||||||
return copyFields
|
return copyFields
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user