29
pkg/probod/pg_config.go
Normal file
29
pkg/probod/pg_config.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package probod
|
||||
|
||||
import (
|
||||
"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"`
|
||||
}
|
||||
)
|
||||
|
||||
func (cfg pgConfig) Options(options ...pg.Option) []pg.Option {
|
||||
opts := []pg.Option{
|
||||
pg.WithAddr(cfg.Addr),
|
||||
pg.WithUser(cfg.Username),
|
||||
pg.WithPassword(cfg.Password),
|
||||
pg.WithDatabase(cfg.Database),
|
||||
pg.WithPoolSize(cfg.PoolSize),
|
||||
}
|
||||
|
||||
opts = append(opts, options...)
|
||||
|
||||
return opts
|
||||
}
|
||||
@@ -2,9 +2,11 @@ package probod
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"go.gearno.de/kit/log"
|
||||
"go.gearno.de/kit/pg"
|
||||
"go.gearno.de/kit/unit"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
@@ -15,6 +17,7 @@ type (
|
||||
}
|
||||
|
||||
config struct {
|
||||
Pg pgConfig `json:"pg"`
|
||||
}
|
||||
)
|
||||
|
||||
@@ -24,7 +27,17 @@ var (
|
||||
)
|
||||
|
||||
func New() *Implm {
|
||||
return &Implm{}
|
||||
return &Implm{
|
||||
cfg: config{
|
||||
Pg: pgConfig{
|
||||
Addr: "localhost:5432",
|
||||
Username: "probod",
|
||||
Password: "probod",
|
||||
Database: "probod",
|
||||
PoolSize: 100,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (impl *Implm) GetConfiguration() any {
|
||||
@@ -38,6 +51,17 @@ func (impl *Implm) Run(
|
||||
tp trace.TracerProvider,
|
||||
) error {
|
||||
|
||||
_, err := pg.NewClient(
|
||||
impl.cfg.Pg.Options(
|
||||
pg.WithLogger(l),
|
||||
pg.WithRegisterer(r),
|
||||
pg.WithTracerProvider(tp),
|
||||
)...,
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot create pg client: %w", err)
|
||||
}
|
||||
|
||||
l.InfoCtx(parentCtx, "started")
|
||||
|
||||
<-parentCtx.Done()
|
||||
|
||||
Reference in New Issue
Block a user