From b49a2e7537fff453de61f1d816db0280972b04e5 Mon Sep 17 00:00:00 2001 From: Farokh Date: Tue, 25 Aug 2026 10:51:39 +0200 Subject: [PATCH] go fix ./... --- dbintf.go | 6 +++--- sqlparser/parser.go | 9 ++------- sqltest/fixture.go | 12 ++++++------ sqltest/intf.go | 6 +++--- sqltest/querydump.go | 30 +++++++++++++++--------------- 5 files changed, 29 insertions(+), 34 deletions(-) diff --git a/dbintf.go b/dbintf.go index 8257e11..85e2ef5 100644 --- a/dbintf.go +++ b/dbintf.go @@ -6,9 +6,9 @@ import ( ) type DB interface { - ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error) - QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error) - QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row + ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error) + QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error) + QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row Conn(ctx context.Context) (*sql.Conn, error) BeginTx(ctx context.Context, txOptions *sql.TxOptions) (*sql.Tx, error) } diff --git a/sqlparser/parser.go b/sqlparser/parser.go index 40eebe9..ce74372 100644 --- a/sqlparser/parser.go +++ b/sqlparser/parser.go @@ -10,6 +10,7 @@ import ( "fmt" "io/fs" "regexp" + "slices" "sort" "strings" ) @@ -637,13 +638,7 @@ func ParseFilesystems(fslst []fs.FS, includeTags []string) (filenames []string, func matchesIncludeTags(required []string, got []string) bool { for _, r := range required { - found := false - for _, g := range got { - if g == r { - found = true - break - } - } + found := slices.Contains(got, r) if !found { return false } diff --git a/sqltest/fixture.go b/sqltest/fixture.go index 693e601..32d975a 100644 --- a/sqltest/fixture.go +++ b/sqltest/fixture.go @@ -16,11 +16,11 @@ import ( type StdoutLogger struct { } -func (s StdoutLogger) Printf(format string, v ...interface{}) { +func (s StdoutLogger) Printf(format string, v ...any) { fmt.Printf(format, v...) } -func (s StdoutLogger) Println(v ...interface{}) { +func (s StdoutLogger) Println(v ...any) { fmt.Println(v...) } @@ -102,8 +102,8 @@ func (f *Fixture) RunMigrations() { if err != nil { panic(err) } - parts := strings.Split(string(migrationSql), "\ngo\n") - for _, p := range parts { + parts := strings.SplitSeq(string(migrationSql), "\ngo\n") + for p := range parts { _, err = f.DB.Exec(p) if err != nil { fmt.Println(p) @@ -117,8 +117,8 @@ func (f *Fixture) RunMigrationFile(filename string) { if err != nil { panic(err) } - parts := strings.Split(string(migrationSql), "\ngo\n") - for _, p := range parts { + parts := strings.SplitSeq(string(migrationSql), "\ngo\n") + for p := range parts { _, err = f.DB.Exec(p) if err != nil { fmt.Println(p) diff --git a/sqltest/intf.go b/sqltest/intf.go index 1d0044a..8c5cebc 100644 --- a/sqltest/intf.go +++ b/sqltest/intf.go @@ -6,10 +6,10 @@ import ( ) type CtxExecer interface { - ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error) + ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error) } type CtxQuerier interface { - QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error) - QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row + QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error) + QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row } diff --git a/sqltest/querydump.go b/sqltest/querydump.go index 77fb874..5d82088 100644 --- a/sqltest/querydump.go +++ b/sqltest/querydump.go @@ -11,19 +11,19 @@ import ( "github.com/alecthomas/repr" ) -type MapRow map[string]interface{} +type MapRow map[string]any type MapRows []MapRow -type Row []interface{} +type Row []any type Rows []Row -func runQuery(dbi interface{}, qry string, args ...interface{}) *sql.Rows { +func runQuery(dbi any, qry string, args ...any) *sql.Rows { switch q := dbi.(type) { case CtxQuerier: rows, err := q.QueryContext(context.Background(), qry, args...) if err != nil { - panic(fmt.Sprintf("runQuery, query: %s \n\n arguments:%+v \n\n error: %s", qry, args, err)) + panic(fmt.Sprintf("runQuery, query: %s \n\n arguments:%+v \n\n error: %s", qry, args, err)) } return rows default: @@ -44,15 +44,15 @@ func RowIteratorToSlice(rows *sql.Rows) (columns []string, result Rows) { panic(fmt.Sprintf("RowIteratorToSlice: while getting columns types: %s", err)) } n := len(columns) - rowValues := make([]interface{}, n, n) - pointers := make([]interface{}, n, n) - for i := 0; i < len(columns); i++ { + rowValues := make([]any, n, n) + pointers := make([]any, n, n) + for i := range columns { pointers[i] = &rowValues[i] } for rows.Next() { err = rows.Scan(pointers...) if err != nil { - panic(fmt.Sprintf("RowIteratorToSlice: while scanning: %s", err)) + panic(fmt.Sprintf("RowIteratorToSlice: while scanning: %s", err)) } var row Row @@ -96,7 +96,7 @@ func DumpRows(rows *sql.Rows) { if len(parsedRows) > 0 { for _, row := range parsedRows { for i, value := range row { - var val interface{} + var val any switch v := value.(type) { case string: val = repr.String(v) @@ -113,11 +113,11 @@ func DumpRows(rows *sql.Rows) { } // Returns the result of a query as a loosely typed structure, for use with test code -func QueryMaps(dbi CtxQuerier, qry string, args ...interface{}) MapRows { +func QueryMaps(dbi CtxQuerier, qry string, args ...any) MapRows { return RowsMap(RowIteratorToSlice(runQuery(dbi, qry, args...))) } -func Query(dbi CtxQuerier, qry string, args ...interface{}) Rows { +func Query(dbi CtxQuerier, qry string, args ...any) Rows { _, rows := RowIteratorToSlice(runQuery(dbi, qry, args...)) // do not use nil but a zero-length slice (for backwards compatability as of this writing, wasn't a conscious decision // at the time it was done) @@ -127,21 +127,21 @@ func Query(dbi CtxQuerier, qry string, args ...interface{}) Rows { return rows } -func QueryInt(dbi CtxQuerier, qry string, args ...interface{}) (result int) { +func QueryInt(dbi CtxQuerier, qry string, args ...any) (result int) { if err := dbi.QueryRowContext(context.Background(), qry, args...).Scan(&result); err != nil { panic(fmt.Sprintf("QueryInt, query: %s\n\n arguments:%+v\n\n error: %s", qry, args, err)) } return } -func QueryString(dbi CtxQuerier, qry string, args ...interface{}) (result string) { +func QueryString(dbi CtxQuerier, qry string, args ...any) (result string) { if err := dbi.QueryRowContext(context.Background(), qry, args...).Scan(&result); err != nil { panic(fmt.Sprintf("QueryString, query: %s\n\n arguments:%+v\n\n error: %s", qry, args, err)) } return } -func QueryTime(dbi CtxQuerier, qry string, args ...interface{}) (result time.Time) { +func QueryTime(dbi CtxQuerier, qry string, args ...any) (result time.Time) { if err := dbi.QueryRowContext(context.Background(), qry, args...).Scan(&result); err != nil { panic(fmt.Sprintf("QueryTime, query: %s\n\n arguments:%+v\n\n error: %s", qry, args, err)) } @@ -149,7 +149,7 @@ func QueryTime(dbi CtxQuerier, qry string, args ...interface{}) (result time.Tim } // Dump result of query to output -func QueryDump(dbi interface{}, qry string, args ...interface{}) { +func QueryDump(dbi any, qry string, args ...any) { fmt.Println("============================") fmt.Println(qry) fmt.Println("============================")