postgresservice

package
v2.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package postgresservice preserves the released service-adapter path. New code should import github.com/faustbrian/go-postgres/v2/adapters/service.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidOptions identifies invalid adapter construction.
	// Deprecated: import github.com/faustbrian/go-postgres/v2/adapters/service.
	ErrInvalidOptions = errors.New("invalid postgres service options")
	// ErrUnavailable identifies a pool that has not started or is stopping.
	// 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

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

func New(options Options) (*Adapter, error)

New delegates to the canonical service adapter.

Deprecated: import github.com/faustbrian/go-postgres/v2/adapters/service.

Example
package main

import (
	"context"
	"fmt"

	"github.com/faustbrian/go-postgres/v2"
	"github.com/faustbrian/go-postgres/v2/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) Component

func (adapter *Adapter) Component() service.Component

Component returns the ordered service lifecycle component.

func (*Adapter) Pool

func (adapter *Adapter) Pool() (Resource, bool)

Pool returns the current pool after successful component startup.

func (*Adapter) Readiness

func (adapter *Adapter) Readiness() service.ReadinessCheck

Readiness returns an opt-in dependency check for the active pool.

type Constructor

type Constructor func(context.Context) (Resource, error)

Constructor acquires a pool whose ownership transfers after a successful return. Deprecated: import github.com/faustbrian/go-postgres/v2/adapters/service.

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.
	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

type OptionsError struct {
	Field  string
	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

type Resource interface {
	Ping(context.Context) error
	Close(context.Context) error
}

Resource is the released adapter resource contract. Deprecated: import github.com/faustbrian/go-postgres/v2/adapters/service.

type StartupError

type StartupError struct {
	Validation error
	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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL