config

package
v1.5.4 Latest Latest
Warning

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

Go to latest
Published: May 4, 2023 License: ISC Imports: 7 Imported by: 0

Documentation

Overview

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultConfigPath added in v1.5.3

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 LoadFile

func LoadFile(path string) error

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

func LoadFileFor added in v1.5.3

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.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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