5 Commits
github ... main

Author SHA1 Message Date
e7df1aac7d fix format 2025-11-05 20:06:06 +01:00
2e3986f227 fix releaser 2025-11-05 19:59:54 +01:00
581956c8ec giv it a version 2025-11-05 19:55:35 +01:00
d2a98920a9 fix linting 2025-11-05 19:50:20 +01:00
d4300204cd add ci pipelines 2025-11-05 19:40:31 +01:00
4 changed files with 130 additions and 6 deletions

54
.goreleaser.yaml Normal file
View File

@@ -0,0 +1,54 @@
# vim: set ts=2 sw=2 tw=0 fo=cnqoj
version: 2
before:
hooks:
- go mod tidy
gitea_urls:
api: https://codeberg.org/api/v1
download: https://codeberg.org
builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- darwin
- freebsd
archives:
- formats: [binary]
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}_{{ .Tag }}
wrap_in_directory: true
changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"
groups:
- title: Improved
regexp: '^.*?(feat|add|new)(\([[:word:]]+\))??!?:.+$'
order: 0
- title: Fixed
regexp: '^.*?(bug|fix)(\([[:word:]]+\))??!?:.+$'
order: 1
- title: Changed
order: 999
release:
header: "# Release Notes"
footer: >-
---
Full Changelog: [{{ .PreviousTag }}...{{ .Tag }}](https://codeberg.org/scip/pgidler/compare/{{ .PreviousTag }}...{{ .Tag }})

28
.woodpecker/build.yaml Normal file
View File

@@ -0,0 +1,28 @@
matrix:
platform:
- linux/amd64
goversion:
- 1.24
labels:
platform: ${platform}
steps:
build:
when:
event: [push]
image: golang:${goversion}
commands:
- go get
- go build
linter:
when:
event: [push]
image: golang:${goversion}
commands:
- curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | sh -s -- -b $(go env GOPATH)/bin v2.5.0
- golangci-lint --version
- golangci-lint run ./...
depends_on: [build]

15
.woodpecker/release.yaml Normal file
View File

@@ -0,0 +1,15 @@
# build release
labels:
platform: linux/amd64
steps:
goreleaser:
image: goreleaser/goreleaser
when:
event: [tag]
environment:
GITEA_TOKEN:
from_secret: DEPLOY_TOKEN
commands:
- goreleaser release --clean --verbose

39
main.go
View File

@@ -32,6 +32,7 @@ import (
"database/sql"
"fmt"
"log"
"os"
"sync"
"time"
@@ -39,6 +40,8 @@ import (
flag "github.com/spf13/pflag"
)
const version = "v0.0.2"
type Tableschema struct {
Name string
}
@@ -60,8 +63,9 @@ func main() {
var optPort int
var optMaxconnections int
var optTimeout int
var optIdleTransaction bool
var optIdleTransaction, shversion bool
var ctx context.Context
var cancel context.CancelFunc
var conn string
flag.StringVarP(&optPasswd, "password", "p", "", "Password of the database user")
@@ -70,11 +74,17 @@ func main() {
flag.StringVarP(&optServer, "server", "s", "localhost", "Server")
flag.IntVarP(&optMaxconnections, "client", "c", 500, "Number of concurrent users")
flag.IntVarP(&optPort, "port", "P", 5432, "TCP Port")
flag.IntVarP(&optTimeout, "timeout", "t", 0, "Wether to stop the clients after N seconds")
flag.IntVarP(&optTimeout, "timeout", "t", 0, "Whether to stop the clients after N seconds")
flag.BoolVarP(&optIdleTransaction, "idletransaction", "i", false, "Wether to stay in idle in transaction state")
flag.BoolVarP(&shversion, "version", "v", false, "show version")
flag.Parse()
if shversion {
fmt.Printf("pgidler version %s\n", version)
os.Exit(0)
}
if optServer != "" {
conn = fmt.Sprintf(NetConnection, optUser, optDatabase, optPasswd, optServer, optPort)
} else {
@@ -86,12 +96,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 +118,10 @@ func main() {
}
wg.Wait()
if cancel != nil {
cancel()
}
}
func dbClient(ctx context.Context, conn string, idle bool) {
@@ -125,7 +142,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 +155,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 +163,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)
}
}
}