From d2a98920a9edbdff44245aebc174b8c9336b6951 Mon Sep 17 00:00:00 2001 From: Thomas von Dein Date: Wed, 5 Nov 2025 19:50:20 +0100 Subject: [PATCH] fix linting --- .woodpecker/build.yaml | 8 -------- main.go | 26 ++++++++++++++++++++++---- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/.woodpecker/build.yaml b/.woodpecker/build.yaml index e20cc6f..d635e43 100644 --- a/.woodpecker/build.yaml +++ b/.woodpecker/build.yaml @@ -26,11 +26,3 @@ steps: - golangci-lint run ./... depends_on: [build] - test: - when: - event: [push] - image: golang:${goversion} - commands: - - go get - - go test -v -cover - depends_on: [build,linter] diff --git a/main.go b/main.go index c910fc9..4e4b585 100644 --- a/main.go +++ b/main.go @@ -62,6 +62,7 @@ func main() { var optTimeout int var optIdleTransaction bool var ctx context.Context + var cancel context.CancelFunc var conn string flag.StringVarP(&optPasswd, "password", "p", "", "Password of the database user") @@ -86,12 +87,15 @@ func main() { if err != nil { log.Fatal(err) } - db.Close() + + if err := db.Close(); err != nil { + log.Fatal(err) + } log.Printf("DB Connection works, firing up %d clients\n", optMaxconnections) if optTimeout > 0 { - ctx, _ = context.WithTimeout(context.Background(), time.Duration(optTimeout)*time.Second) + ctx, cancel = context.WithTimeout(context.Background(), time.Duration(optTimeout)*time.Second) log.Printf("Clients will be killed after %d seconds", optTimeout) } else { ctx = context.TODO() @@ -105,6 +109,10 @@ func main() { } wg.Wait() + + if cancel != nil { + cancel() + } } func dbClient(ctx context.Context, conn string, idle bool) { @@ -125,7 +133,12 @@ func dbClient(ctx context.Context, conn string, idle bool) { if err != nil { log.Fatal(err) } - defer rows.Close() + defer func() { + if err := rows.Close(); err != nil { + log.Fatal(err) + } + }() + //log.Println("Got rows") for rows.Next() { @@ -133,6 +146,7 @@ func dbClient(ctx context.Context, conn string, idle bool) { if err := rows.Scan(&T.Name); err != nil { log.Fatal(err) } + //log.Printf("Got table %s\n", T.Name) for i := 0; i < Maxloop; i++ { @@ -140,7 +154,11 @@ func dbClient(ctx context.Context, conn string, idle bool) { if err != nil { log.Fatal(err) } - rows.Close() // ignore result + + // ignore result + if err := rows.Close(); err != nil { + log.Fatal(err) + } } }