termconfig

package
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 11 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package termconfig loads layered configuration for terminull apps.

Precedence, low to high: Defaults, config files, environment, Overrides (parsed CLI flags, handed over by package app).

Files are searched in order and every existing file is layered, so project-local settings win over user-global ones:

  1. explicit --config path (missing file is an error)
  2. home dotfile: ~/.APPNAME.yaml
  3. user config dir: %APPDATA%/APPNAME/APPNAME.yaml, ~/.config/APPNAME/APPNAME.yaml, ~/Library/Application Support/...
  4. working directory: ./APPNAME.yaml then ./.APPNAME.yaml

Environment variables use APPNAME_ prefixes: APPNAME_DB_HOST becomes db.host. Numeric-looking and true/false values become typed.

Unknown keys fail loudly, but only at UnmarshalStrict time: typos in files or env surface as errors naming the key instead of silent zero values.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// contains filtered or unexported fields
}

Config wraps the layered koanf instance.

func Load

func Load(opts Options) (*Config, error)

Load layers defaults, files, env, and overrides in that order.

func (*Config) All

func (c *Config) All() map[string]any

All returns every layered key for dumps and debugging.

func (*Config) Bool

func (c *Config) Bool(path string) bool

Bool returns the value at path as a bool, false when absent.

func (*Config) Exists

func (c *Config) Exists(path string) bool

Exists reports whether the dotted path is set.

func (*Config) Float64

func (c *Config) Float64(path string) float64

Float64 returns the value at path as a float64, 0 when absent.

func (*Config) Get

func (c *Config) Get(path string) any

Get returns the value at the dotted path, or nil when absent.

func (*Config) Int

func (c *Config) Int(path string) int

Int returns the value at path as an int, 0 when absent.

func (*Config) String

func (c *Config) String(path string) string

String returns the value at path as a string, "" when absent.

func (*Config) Strings

func (c *Config) Strings(path string) []string

Strings returns the value at path as a string slice.

func (*Config) Unmarshal

func (c *Config) Unmarshal(target any) error

Unmarshal decodes into target with weak typing (env strings convert). Unknown keys are ignored; use UnmarshalStrict to reject them.

func (*Config) UnmarshalStrict

func (c *Config) UnmarshalStrict(target any) error

UnmarshalStrict decodes like Unmarshal but fails naming any key that has no matching struct field, catching typos in files and env.

type Options

type Options struct {
	// AppName drives file names and the env prefix: "deploy" looks for
	// deploy.yaml and reads DEPLOY_ variables.
	AppName string
	// ConfigFile is an explicit --config path. Missing file is an error.
	ConfigFile string
	// Defaults is the lowest-precedence layer.
	Defaults map[string]any
	// Overrides is the highest-precedence layer (parsed CLI flags).
	Overrides map[string]any
	// EnvPrefix overrides the derived UPPER(AppName)+"_" prefix.
	EnvPrefix string
	// Environ injects environment lines for tests; nil uses os.Environ.
	Environ []string
	// EnvironFunc injects an environ function; takes precedence over Environ.
	EnvironFunc func() []string
}

Options tunes a Load call. Zero value loads nothing but empty defaults.

Directories

Path Synopsis
internal
koanf/confmap
Package confmap implements a koanf.Provider that takes nested and flat map[string]any config maps and provides them to koanf.
Package confmap implements a koanf.Provider that takes nested and flat map[string]any config maps and provides them to koanf.
koanf/env
Package env implements a koanf.Provider that reads environment variables as conf maps.
Package env implements a koanf.Provider that reads environment variables as conf maps.
koanf/file
Package file implements a koanf.Provider that reads raw bytes from files on disk to be used with a koanf.Parser to parse into conf maps.
Package file implements a koanf.Provider that reads raw bytes from files on disk to be used with a koanf.Parser to parse into conf maps.
koanf/maps
Package maps provides reusable functions for manipulating nested map[string]interface{} maps are common unmarshal products from various serializers such as json, yaml etc.
Package maps provides reusable functions for manipulating nested map[string]interface{} maps are common unmarshal products from various serializers such as json, yaml etc.
koanf/yaml
Package yaml implements a koanf.Parser that parses YAML bytes as conf maps.
Package yaml implements a koanf.Parser that parses YAML bytes as conf maps.
mapstructure
Package mapstructure exposes functionality to convert one arbitrary Go type into another, typically to convert a map[string]any into a native Go structure.
Package mapstructure exposes functionality to convert one arbitrary Go type into another, typically to convert a map[string]any into a native Go structure.
reflectwalk
reflectwalk is a package that allows you to "walk" complex structures similar to how you may "walk" a filesystem: visiting every element one by one and calling callback functions allowing you to handle and manipulate those elements.
reflectwalk is a package that allows you to "walk" complex structures similar to how you may "walk" a filesystem: visiting every element one by one and calling callback functions allowing you to handle and manipulate those elements.

Jump to

Keyboard shortcuts

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