pg

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package pg supplies the standard libpq PG* flag set and the connection Config it binds. Consumers embed Config in a command config, list Binder{Config: &cfg}.Flags() in the command's flags, and pass Config.ConnString() to their PostgreSQL driver; empty fields are omitted so the driver falls back to the PG* environment variables (and ~/.pgpass / ~/.pg_service.conf). Opening a pool stays with the consumer.

Index

Constants

View Source
const (
	HostFlag     = "pghost"
	PortFlag     = "pgport"
	DatabaseFlag = "pgdatabase"
	UserFlag     = "pguser"
	PasswordFlag = "pgpassword"
	SSLModeFlag  = "pgsslmode"
)

PG* flag names (constants for reuse in tests/help).

Variables

This section is empty.

Functions

This section is empty.

Types

type Binder

type Binder struct {
	Config *Config
}

Binder binds the standard libpq-compatible PG* flags to a shared Config. The destination pointer lives in a field (not a parameter) so the binder itself travels by value while the flags still write into the one Config instance the command's action reads — the same binder pattern as app.LoggerFlags.

func (Binder) Flags

func (b Binder) Flags() []cli.Flag

Flags builds the PG* flag set bound to the Config destination. The env vars are the canonical PG* names (not app-prefixed) so the flags work with psql, pgx, and any libpq tool.

type Config

type Config struct {
	Host     host
	Name     name
	User     user
	Password password
	SSLMode  sslMode
	Port     port
}

Config holds libpq-compatible PostgreSQL connection parameters, bound from the standard PG* flags. Fields are exported because the CLI binds them by pointer; the field types are unexported domain types (see types.go).

func (Config) ConnString

func (c Config) ConnString() string

ConnString constructs a libpq KV connection string from the explicit flag values. Empty fields are omitted so the driver falls back to the PG* environment variables (and ~/.pgpass / ~/.pg_service.conf).

Jump to

Keyboard shortcuts

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