Documentation
¶
Overview ¶
Package postgresservice adapts PostgreSQL pools to the service lifecycle.
Constructor results are owned by the adapter. Existing pools remain shared unless ownership is explicitly transferred. Startup validation, readiness, and shutdown use caller and service contexts plus the pool's own bounds. The adapter performs no retries, closes owned pools exactly once, and never closes shared pools.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidOptions identifies invalid adapter construction. ErrInvalidOptions = errors.New("invalid postgres service options") ErrUnavailable = errors.New("postgres service pool unavailable") )
Functions ¶
This section is empty.
Types ¶
type Adapter ¶
type Adapter struct {
// contains filtered or unexported fields
}
Adapter owns the lifecycle state for one PostgreSQL pool.
func New ¶
New validates and constructs an inert adapter.
Example ¶
package main
import (
"context"
"fmt"
"github.com/faustbrian/go-postgres"
"github.com/faustbrian/go-postgres/postgresservice"
)
var _ postgresservice.Resource = (*postgres.Pool)(nil)
func main() {
pool := &resource{}
adapter, err := postgresservice.New(postgresservice.Options{
Name: "database",
Pool: pool,
TransferOwnership: true,
StartupPing: true,
})
if err != nil {
fmt.Println("adapter setup failed")
return
}
component := adapter.Component()
_ = component.Start(context.Background())
check := adapter.Readiness()
_ = check.Run(context.Background())
_ = component.Stop(context.Background())
fmt.Println(pool.pings, pool.closes)
}
Output: 2 1
func (*Adapter) Readiness ¶
func (adapter *Adapter) Readiness() service.ReadinessCheck
Readiness returns an opt-in dependency check for the active pool. Callers decide whether to include it in service.Plan.Readiness.
type Constructor ¶
Constructor acquires a pool whose ownership transfers to the adapter only after a successful return.
type Options ¶
type Options struct {
// Name is the secret-safe component and readiness-check name.
Name string
// Construct acquires an adapter-owned pool during component startup.
Construct Constructor
// Pool supplies an existing pool. The caller retains ownership unless
// TransferOwnership is true.
Pool Resource
// TransferOwnership closes Pool during shutdown and failed startup.
TransferOwnership bool
// StartupPing validates the acquired pool before startup succeeds.
StartupPing bool
}
Options configure one PostgreSQL lifecycle adapter.
type OptionsError ¶
OptionsError identifies one rejected option.
func (*OptionsError) Error ¶
func (err *OptionsError) Error() string
Error returns a secret-safe construction diagnostic.
func (*OptionsError) Unwrap ¶
func (err *OptionsError) Unwrap() error
Unwrap exposes the stable option classification.
type StartupError ¶
StartupError preserves validation and partial-cleanup failures without formatting either potentially sensitive cause.
func (*StartupError) Error ¶
func (err *StartupError) Error() string
Error returns a secret-safe startup diagnostic.
func (*StartupError) Unwrap ¶
func (err *StartupError) Unwrap() []error
Unwrap preserves both failures for errors.Is and errors.As.