config

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package config standardizes 12-factor configuration on jessevdk/go-flags: a single options struct whose fields carry `long`/`env`/`default`/`description` tags, so the same definition drives CLI flags, environment variables, and `--help`. Nested groups use `group`/`namespace`/`env-namespace` tags (e.g. a group with env-namespace "DB" and a field with env "USER" reads DB_USER).

For local development, LoadDotenv seeds the environment from a .env file; real environment variables always take precedence.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsHelp

func IsHelp(err error) bool

IsHelp reports whether err is the benign "help requested" error, which callers should treat as a clean exit.

func LoadDotenv

func LoadDotenv(files ...string) error

LoadDotenv loads the given .env files (default ".env") into the process environment if present. Missing files are ignored, and existing environment variables are never overwritten — in production values come from the orchestrator, not a file.

func NewParser

func NewParser(data any) *flags.Parser

NewParser builds a go-flags parser with a deterministic env-namespace delimiter ("_") so nested env names are predictable (DB_USER, HTTP_ADDR, ...). data is typically a pointer to an options struct, optionally containing `command:`-tagged subcommands that implement flags.Commander.

func Parse

func Parse(data any, dotenvFiles ...string) error

Parse loads the dotenv files (if any) then parses os.Args into data, dispatching any matched subcommand's Execute. It returns the go-flags error unchanged so callers can detect --help via IsHelp.

func Reset

func Reset(keys ...string)

Reset removes variables from the environment, e.g. to drop a secret after it has been consumed so it cannot leak into child processes or crash dumps.

Types

This section is empty.

Jump to

Keyboard shortcuts

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