Documentation
¶
Overview ¶
Package configutil contains helpers for reading configuration for programs. It contains defaults for common config locations, and reads the files as yaml or json into a config struct you create for your program.
Index ¶
- Constants
- Variables
- func Deserialize(ext string, r io.Reader, ref Any) error
- func IsConfigPathUnset(err error) bool
- func IsIgnored(err error) bool
- func IsInvalidConfigExtension(err error) bool
- func IsNotExist(err error) bool
- func Paths(defaults ...string) (output []string)
- func PathsWithDefaults(paths ...string) []string
- func Read(ref Any, paths ...string) error
- func ReadFromReader(ref Any, r io.Reader, ext string) error
- func TryReadFromPaths(ref Any, paths ...string) (path string, err error)
- type Any
- type Labels
- type Vars
Constants ¶
const ( // EnvVarConfigPath is the env var for configs. EnvVarConfigPath = "CONFIG_PATH" // ExtensionJSON is a file extension. ExtensionJSON = ".json" // ExtensionYAML is a file extension. ExtensionYAML = ".yaml" // ExtensionYML is a file extension. ExtensionYML = ".yml" )
const ( // ErrConfigPathUnset is a common error. ErrConfigPathUnset = exception.Class("config path unset") // ErrInvalidConfigExtension is a common error. ErrInvalidConfigExtension = exception.Class("config extension invalid") )
Variables ¶
var ( // DefaultPaths are default path locations. // They are tested and read in order, so the later // paths will override data found in the earlier ones. DefaultPaths = []string{ "/var/secrets/config.yml", "/var/secrets/config.yaml", "/var/secrets/config.json", "./_config/config.yml", "./_config/config.yaml", "./_config/config.json", "./config.yml", "./config.yaml", "./config.json", } )
Functions ¶
func Deserialize ¶
Deserialize deserializes a config.
func IsConfigPathUnset ¶
IsConfigPathUnset returns if an error is an ErrConfigPathUnset.
func IsInvalidConfigExtension ¶
IsInvalidConfigExtension returns if an error is an ErrInvalidConfigExtension.
func IsNotExist ¶
IsNotExist returns if an error is an os.ErrNotExist.
func Paths ¶
Paths returns config paths. The results are the provided defaults and the `CONFIG_PATH` environment variable as a csv if it's set.
func PathsWithDefaults ¶
PathsWithDefaults returns the default paths and additional optional paths.
func Read ¶
Read reads a config from optional path(s). Paths will be tested from a standard set of defaults (ex. config.yml) and optionally a csv named in the `CONFIG_PATH` environment variable.
func ReadFromReader ¶
ReadFromReader reads a config from a given reader.