config

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package config is the one place the process reads its environment. Every setting has an CARTOGRAPH_ variable, a flag that overrides it, and a default that works on a laptop, in that order of precedence: flag, environment, default. Nothing else in the server calls os.Getenv for configuration.

This is the twelve-factor "config" factor: a deployment differs from another by environment alone, and the same binary runs in both.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Addr is the listen address. CARTOGRAPH_ADDR, default ":8080". A bare
	// port ("8080", what PORT-style platforms hand out) is accepted, and
	// "unix:///path/to.sock" listens on a UNIX domain socket instead.
	Addr string

	// Vault is the directory of manifests to serve, or a SQLite file.
	// CARTOGRAPH_VAULT, default ".". A positional argument on the command line
	// wins over both.
	Vault string

	// Watch reloads manifests when their files change on disk.
	// CARTOGRAPH_WATCH, default true.
	Watch bool

	// Chromium is the browser to print PDFs with. CARTOGRAPH_CHROMIUM, default
	// empty: the printer then tries the vault's settings, CHROMIUM, then
	// the PATH.
	Chromium string

	// LogFormat is "text" or "json". CARTOGRAPH_LOG_FORMAT, default "text".
	// Logs always go to stdout; the environment decides where they end up.
	LogFormat string

	// LogLevel is debug, info, warn or error. CARTOGRAPH_LOG_LEVEL, default
	// "info".
	LogLevel string

	// ShutdownTimeout is how long in-flight requests get after SIGTERM.
	// CARTOGRAPH_SHUTDOWN_TIMEOUT, default 10s.
	ShutdownTimeout time.Duration

	// Auth selects the authenticator: "none" (every request is the
	// vault's operator) or "proxy" (the identity is the value of
	// AuthProxyHeader, set by an authenticating reverse proxy that is the
	// only way to reach the server). CARTOGRAPH_AUTH, default "none".
	Auth string

	// AuthProxyHeader is the header the proxy authenticator reads.
	// CARTOGRAPH_AUTH_PROXY_HEADER, default "X-Forwarded-User".
	AuthProxyHeader string

	// Authz selects the authorizer: "allow" (every principal may do
	// everything) or "roles" (ReadRoles and WriteRoles decide; an anonymous
	// principal is refused, so pair it with an authenticator).
	// CARTOGRAPH_AUTHZ, default "allow".
	Authz string

	// ReadRoles and WriteRoles are comma-separated role names for the
	// roles authorizer. CARTOGRAPH_READ_ROLES (empty: any authenticated
	// principal may read), CARTOGRAPH_WRITE_ROLES (empty: nobody may write).
	ReadRoles  string
	WriteRoles string

	// Codec is the manifest syntax, "yaml" or "json". CARTOGRAPH_CODEC,
	// default "yaml". A vault is written in one codec; changing it is a
	// migration, not a restart.
	Codec string

	// ImportDir, when set, is imported on startup before serving.
	// CARTOGRAPH_IMPORT, default empty.
	ImportDir string
}

Config is everything `cartograph serve` can be told from outside.

func Defaults

func Defaults() Config

Defaults is the configuration a laptop needs: serve the current directory on :8080, text logs, no authentication.

func FromEnv

func FromEnv(getenv Getenv) (Config, error)

FromEnv returns Defaults overridden by every CARTOGRAPH_ variable getenv knows. A variable with an unparseable value is an error that names it.

func (*Config) Flags

func (c *Config) Flags(fs *flag.FlagSet)

Flags binds every setting to fs, with the current values as defaults, so a flag overrides the environment and the environment overrides the default.

func (Config) IsUnix

func (c Config) IsUnix() bool

IsUnix reports whether Addr names a UNIX domain socket (unix:///path).

func (Config) ListenAddr

func (c Config) ListenAddr() string

ListenAddr normalises Addr: a bare port becomes ":port", which is what a platform that hands out PORT expects to work.

func (Config) Validate

func (c Config) Validate() error

Validate refuses a value no adapter can act on.

type Getenv

type Getenv func(key string) string

Getenv is the shape of os.Getenv, so a test can supply its own.

Jump to

Keyboard shortcuts

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