Clients
// clients/postgres/postgres.go
package postgres
import (
"context"
"github.com/jackc/pgx/v5/pgxpool"
)
// Open owns application-specific setup but returns the canonical pool type.
// Do not shadow Query, Exec, Begin, or the rest of pgxpool.Pool.
func Open(ctx context.Context, databaseURL string) (*pgxpool.Pool, error) {
config, err := pgxpool.ParseConfig(databaseURL)
if err != nil {
return nil, err
}
// Install app-specific limits, tracing, or hooks here when needed.
return pgxpool.NewWithConfig(ctx, config)
}
// init/dependencies.go
pool, err := lazydeps.Service(deps, "postgres", func(ctx context.Context) (
context.Context,
*pgxpool.Pool,
error,
context.CancelFunc,
) {
pool, err := postgres.Open(ctx, os.Getenv("DATABASE_URL"))
if err != nil {
return ctx, nil, err, nil
}
return ctx, pool, nil, pool.Close
})
Use service-owned types for business meaning, client-owned types for normalized integration values, and upstream types when they are already the best Go abstraction. Do not add an interface or wrapper unless it owns useful behavior or substitution.
SEE OTHERS: Services