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

@@ -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
}