Update kit with new pg config

Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
Bryan Frimin
2026-04-22 22:29:53 +02:00
parent 7be92defcc
commit 990dfa8438
12 changed files with 101 additions and 29 deletions

View File

@@ -17,18 +17,22 @@ package probod
import (
"crypto/x509"
"encoding/pem"
"time"
"go.gearno.de/kit/pg"
)
type PgConfig struct {
Addr string `json:"addr"`
Username string `json:"username"`
Password string `json:"password"`
Database string `json:"database"`
PoolSize int32 `json:"pool-size"`
CACertBundle string `json:"ca-cert-bundle"`
Debug bool `json:"debug"`
Addr string `json:"addr"`
Username string `json:"username"`
Password string `json:"password"`
Database string `json:"database"`
PoolSize int32 `json:"pool-size"`
MinPoolSize int32 `json:"min-pool-size"`
MaxConnIdleTimeSeconds int `json:"max-conn-idle-time-seconds"`
MaxConnLifetimeSeconds int `json:"max-conn-lifetime-seconds"`
CACertBundle string `json:"ca-cert-bundle"`
Debug bool `json:"debug"`
}
func (cfg PgConfig) Options(options ...pg.Option) []pg.Option {
@@ -40,6 +44,28 @@ func (cfg PgConfig) Options(options ...pg.Option) []pg.Option {
pg.WithPoolSize(cfg.PoolSize),
}
if cfg.MinPoolSize > 0 {
opts = append(opts, pg.WithMinPoolSize(cfg.MinPoolSize))
}
if cfg.MaxConnIdleTimeSeconds > 0 {
opts = append(
opts,
pg.WithMaxConnIdleTime(
time.Duration(cfg.MaxConnIdleTimeSeconds)*time.Second,
),
)
}
if cfg.MaxConnLifetimeSeconds > 0 {
opts = append(
opts,
pg.WithMaxConnLifetime(
time.Duration(cfg.MaxConnLifetimeSeconds)*time.Second,
),
)
}
if cfg.Debug {
opts = append(opts, pg.WithDebug())
}