package config
import "git.wntrmute.dev/kyle/goutils/config"
Package config implements a simple global configuration system that supports a file with key=value pairs and environment variables. Note that the config system is global.
This package is intended to be used for small daemons: some configuration file is optionally populated at program start, then this is used to transparently look up configuration values from either that file or the environment.
Index ¶
- func DefaultConfigPath(dir, base string) string
- func Get(key string) string
- func GetDefault(key, def string) string
- func ListKeys() []string
- func LoadFile(path string) error
- func LoadFileFor(path, section string, strict bool) error
- func Require(key string) string
- func SetEnvPrefix(pfx string)
Functions ¶
func DefaultConfigPath ¶
DefaultConfigPath returns a sensible default configuration file path.
func Get ¶
Get retrieves a value from either a configuration file or the environment. Note that values from a file will override environment variables.
func GetDefault ¶
GetDefault retrieves a value from either a configuration file or the environment. Note that value from a file will override environment variables. If a value isn't found (e.g. Get returns an empty string), the default value will be used.
func ListKeys ¶
func ListKeys() []string
ListKeys returns a slice of the currently known keys.
func LoadFile ¶
LoadFile scans the file at path for key=value pairs and adds them to the configuration.
func LoadFileFor ¶
LoadFileFor scans the ini file at path, loading the default section and overriding any keys found under section. If strict is true, the named section must exist (i.e. to catch typos in the section name).
func Require ¶
Require retrieves a value from either a configuration file or the environment. If the key isn't present, it will call log.Fatal, printing the missing key.
func SetEnvPrefix ¶
func SetEnvPrefix(pfx string)
SetEnvPrefix sets the prefix for all environment variables; it's assumed to not be needed for files.
Source Files ¶
config.go path_linux.go
Directories ¶
Path | Synopsis |
---|---|
config/iniconf |
- Version
- v1.7.7 (latest)
- Published
- Jun 15, 2024
- Platform
- linux/amd64
- Imports
- 8 packages
- Last checked
- 3 days ago –
Tools for package owners.