spec

package
v1.1.23 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: GPL-2.0, GPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package spec parses and validates the DB_SPECS environment variable: a whitespace-separated list of "host[:port]:dbname:user" tuples describing which PostgreSQL databases to dump and over which network coordinates.

This is the single validation path. There is no second (shell) implementation to drift from, and the rules here are the only thing that stands between operator-supplied config and a pg_dump/psql argv. Passwords are never part of the grammar: libpq resolves them from .pgpass keyed on host:port:dbname:user.

Index

Constants

View Source
const DefaultPort = 5432

DefaultPort is the PostgreSQL port assumed when a spec omits one.

Variables

This section is empty.

Functions

func ServerDir added in v1.1.5

func ServerDir(host string, port int) string

ServerDir is the per-server subdirectory name under DUMP_DIR for a database's dump artifacts, making the on-disk path honor the (host, port) server identity (so two databases that share a name on different servers never map to one file). For a hostname or IPv4 host (the grammar [a-zA-Z0-9_.-] has no ':'), it is "<host>_<port>". For a canonical IPv6 host (the only host kind containing ':'), it is "@<addr-with-colons-as-dashes>_<port>": the '@' prefix (which the host grammar can never produce) keeps IPv6 directories in a namespace disjoint from hostname/IPv4 directories, and ':'->'-' is injective over a canonical IPv6 literal (which never contains '-'). The port is the resolved port and is recovered as the trailing digit run, so distinct (host, port) pairs never collide.

Types

type DBSpec

type DBSpec struct {
	Host      string
	DBName    string
	User      string
	Raw       string // original token, for error reporting and logs
	Invalid   string // non-empty => why this spec is invalid
	Port      int
	Duplicate bool // true => Invalid because it duplicates an earlier host:port:dbname
}

DBSpec is one validated host[:port]:dbname:user tuple. A spec with a non-empty Invalid field failed validation and must never be passed to pg_dump; the orchestrator reports it per-DB and skips it.

func ParseSpecs

func ParseSpecs(raw string) []DBSpec

ParseSpecs splits raw on whitespace and validates each tuple. Every token yields exactly one DBSpec (valid or Invalid); tokens are never dropped silently. Duplicate (host, port, dbname) keys keep the first occurrence and mark later ones Invalid. The returned slice preserves input order.

Jump to

Keyboard shortcuts

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