Documentation
¶
Overview ¶
Package postgresservice preserves the released service-adapter path. New code should import github.com/faustbrian/go-postgres/v2/adapters/service. New delegates the ordered lifecycle while retaining released type and error identities. Existing pools stay shared unless ownership is transferred; constructors own failed acquisition cleanup and successful results transfer.
Index ¶
- Variables
- type Adapterdeprecated
- type Constructordeprecated
- type Optionsdeprecated
- type OptionsErrordeprecated
- type Resourcedeprecated
- type StartupErrordeprecated
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidOptions identifies invalid adapter construction. // // Deprecated: import github.com/faustbrian/go-postgres/v2/adapters/service. ErrInvalidOptions = errors.New("invalid postgres service options") // // Deprecated: import github.com/faustbrian/go-postgres/v2/adapters/service. ErrUnavailable = errors.New("postgres service pool unavailable") )
Functions ¶
This section is empty.
Types ¶
type Adapter
deprecated
type Adapter struct {
// contains filtered or unexported fields
}
Adapter preserves released type identity while delegating behavior to the canonical service adapter.
Deprecated: import github.com/faustbrian/go-postgres/v2/adapters/service.
func New
deprecated
New delegates to the canonical service adapter.
Deprecated: import github.com/faustbrian/go-postgres/v2/adapters/service.
Example ¶
ExampleNew preserves the released adapter path with a fake Resource; new consumers should use adapters/service for the same lifecycle contract.
package main
import (
"context"
"fmt"
"github.com/faustbrian/go-postgres/v2"
"github.com/faustbrian/go-postgres/v2/postgresservice"
)
var _ postgresservice.Resource = (*postgres.Pool)(nil)
// ExampleNew preserves the released adapter path with a fake Resource; new
// consumers should use adapters/service for the same lifecycle contract.
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) Pool ¶
Pool returns a borrowed resource and whether startup succeeded without stopping. The bool is a lifecycle snapshot, not a lease preventing concurrent shutdown; the resource may remain non-nil when inactive. Do not close an adapter-owned resource independently.
func (*Adapter) Readiness ¶
func (adapter *Adapter) Readiness() service.ReadinessCheck
Readiness returns an opt-in dependency check for the active pool. It must be added to the service plan separately; it does not enable startup validation. Inactive resources return ErrUnavailable without Ping. Active resources retain their own context bounds and may race with shutdown after the state snapshot.
type Constructor
deprecated
Constructor acquires a pool whose ownership transfers after a successful return. On an error the adapter does not close a partially returned resource; the constructor must clean up its own failed acquisition.
Deprecated: import github.com/faustbrian/go-postgres/v2/adapters/service.
type Options
deprecated
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; ownership stays with the caller unless
// transferred.
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.
Deprecated: import github.com/faustbrian/go-postgres/v2/adapters/service.
type OptionsError
deprecated
type OptionsError struct {
// Field names the rejected option.
Field string
// Reason describes the option refusal without echoing the supplied pool or name.
Reason string
}
OptionsError identifies a rejected option.
Deprecated: import github.com/faustbrian/go-postgres/v2/adapters/service.
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 Resource
deprecated
type Resource interface {
// Ping checks connectivity using the service-supplied operation context.
Ping(context.Context) error
// Close releases owned resources; implementations must honor their context
// cooperatively.
Close(context.Context) error
}
Resource is the released adapter resource contract.
Deprecated: import github.com/faustbrian/go-postgres/v2/adapters/service.
type StartupError
deprecated
type StartupError struct {
// Validation is the original failed startup ping; inspect under your
// privacy policy.
Validation error
// Cleanup is an owned resource close failure; nil does not add a second cause.
Cleanup error
}
StartupError preserves validation and cleanup failures.
Deprecated: import github.com/faustbrian/go-postgres/v2/adapters/service.
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.