fix linting

This commit is contained in:
2025-11-05 19:50:20 +01:00
parent d4300204cd
commit d2a98920a9
2 changed files with 22 additions and 12 deletions

View File

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

26
main.go
View File

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