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

Functions

func DefaultConfigPath

func DefaultConfigPath(dir, base string) string

DefaultConfigPath returns a sensible default configuration file path.

func Get

func Get(key string) string

Get retrieves a value from either a configuration file or the environment. Note that values from a file will override environment variables.

func GetDefault

func GetDefault(key, def string) string

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

func LoadFile(path string) error

LoadFile scans the file at path for key=value pairs and adds them to the configuration.

func LoadFileFor

func LoadFileFor(path, section string, strict bool) error

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

func Require(key string) string

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

PathSynopsis
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.