Documentation
¶
Overview ¶
Package postgres starts PostgreSQL containers with dockermanage.
Index ¶
- Constants
- type Instance
- type StartOption
- func WithDatabase(database string) StartOption
- func WithHostIP(hostIP string) StartOption
- func WithHostPort(port int) StartOption
- func WithImage(image string) StartOption
- func WithLabel(key, value string) StartOption
- func WithPassword(password string) StartOption
- func WithReadiness(readiness dockermanage.ReadinessFunc) StartOption
- func WithUser(user string) StartOption
Constants ¶
const ( // DefaultImage is the default PostgreSQL image. DefaultImage = "postgres:18-alpine" // DefaultDatabase is the default PostgreSQL database name. DefaultDatabase = "testdb" // DefaultUser is the default PostgreSQL user. DefaultUser = "postgres" // DefaultPassword is the default PostgreSQL password. DefaultPassword = "password1" // ContainerPort is the PostgreSQL port inside the container. ContainerPort = 5432 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Instance ¶
type Instance struct {
// contains filtered or unexported fields
}
Instance is a running PostgreSQL container. Use Instance.URL to connect, and Instance.Container to stop or remove the container, or to run commands in it.
func Start ¶
func Start(ctx context.Context, manager *dockermanage.Manager, options ...StartOption) (_ *Instance, retErr error)
Start starts a PostgreSQL container and waits until it accepts connections. It waits until the ctx deadline, or for 30s after the container starts if ctx has no deadline; the ctx deadline also covers the image pull. If Start fails after it creates the container, it removes the container.
func (*Instance) Container ¶
func (i *Instance) Container() *dockermanage.Container
Container returns the PostgreSQL container.
type StartOption ¶
type StartOption interface {
// contains filtered or unexported methods
}
StartOption configures Start.
func WithDatabase ¶
func WithDatabase(database string) StartOption
WithDatabase sets the database name.
func WithHostIP ¶
func WithHostIP(hostIP string) StartOption
WithHostIP sets the host IP address that the PostgreSQL port is bound to. Defaults to dockermanage.DefaultHostIP. For a remote Docker daemon, use "0.0.0.0".
func WithHostPort ¶
func WithHostPort(port int) StartOption
WithHostPort sets a fixed host port. If unset, Docker picks one.
func WithLabel ¶
func WithLabel(key, value string) StartOption
WithLabel sets one container label. Use it once for each label.
func WithPassword ¶
func WithPassword(password string) StartOption
WithPassword sets the database user password.
func WithReadiness ¶
func WithReadiness(readiness dockermanage.ReadinessFunc) StartOption
WithReadiness replaces the check that Start uses to wait until PostgreSQL is ready. By default, Start runs pg_isready inside the container. Use it for an image that does not include pg_isready, for example with a check that connects with your driver.