Documentation ¶
Index ¶
- func ParseTOML(content []byte) (map[string]interface{}, error)
- func ParseYAML(content []byte) (map[string]interface{}, error)
- type FileParser
- type Sourcer
- func NewDirectorySourcer(dirname string, parser FileParser) Sourcer
- func NewEnvSourcer(prefix string) Sourcer
- func NewFileSourcer(filename string, parser FileParser) Sourcer
- func NewGlobSourcer(pattern string, parser FileParser) Sourcer
- func NewMultiSourcer(sourcers ...Sourcer) Sourcer
- func NewOptionalDirectorySourcer(dirname string, parser FileParser) Sourcer
- func NewOptionalFileSourcer(filename string, parser FileParser) Sourcer
- func NewTOMLFileSourcer(filename string) Sourcer
- func NewYAMLFileSourcer(filename string) Sourcer
- type SourcerFlag
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type FileParser ¶
type Sourcer ¶
type Sourcer interface { // Tags returns a list of tags which are required to get a value from // the source. Order matters. Tags() []string // Get will retrieve a value from the source with the given tag values. // The tag values passed to this method will be in the same order as // returned from the Tags method. The flag return value directs config // population whether or not this value should be treated as missing or // skippable. Get(values []string) (string, SourcerFlag, error) // Assets returns a list of names of assets that compose the sourcer. // This can be a list of matched files that are read, or a token that // denotes a fixed source. Assets() []string // Dump returns the full content of the sourcer. This is used by the // logging package to show the content of the environment and config // files when a value is missing or otherwise illegal. Dump() map[string]string }
Sourcer pulls requested names from a variable source. This can be the environment, a file, a remote server, etc. This can be done on-demand per variable, or a cache of variables can be built on startup and then pulled from a cached mapping as requested.
func NewDirectorySourcer ¶
func NewDirectorySourcer(dirname string, parser FileParser) Sourcer
NewDirectorySourcer creates a sourcer that reads files from a directory. For details on parsing format, refer to NewFileParser. Each file in a directory is read in alphabetical order. Nested directories are ignored when reading direcotry content, and each found regular file is assumed to be parseable by the given FileParser.
func NewEnvSourcer ¶
NewEnvSourcer creates a Sourcer that pulls values from the environment. The environment variable {PREFIX}_{NAME} is read before and, if empty, the environment varaible {NAME} is read as a fallback. The prefix is normalized by replacing all non-alpha characters with an underscore, removing leading and trailing underscores, and collapsing consecutive underscores with a single character.
func NewFileSourcer ¶
func NewFileSourcer(filename string, parser FileParser) Sourcer
NewFileSourcer creates a sourcer that reads content from a file. The format of the file is read by the given FileParser. The content of the file must be an encoding of a map from string keys to JSON-serializable values. If a nil parser is supplied, one will be selected based on the extension of the file. JSON, YAML, and TOML files are supported.
func NewGlobSourcer ¶
func NewGlobSourcer(pattern string, parser FileParser) Sourcer
NewGlobSourcer creates a sourcer that reads all files that match the given glob pattern. Each matching file is read in alphabetical order of path. Each matching pathis assumed to be parseable by the given FileParser.
func NewMultiSourcer ¶
NewMultiSourcer creates a sourcer that reads form each sourcer. The last value found is returned - sourcers should be provided from low priority to high priority.
func NewOptionalDirectorySourcer ¶
func NewOptionalDirectorySourcer(dirname string, parser FileParser) Sourcer
NewOptionalDirectorySourcer creates a directory sourcer if the provided directoy exists. the provided file is not found, a sourcer is returned returns no values.
func NewOptionalFileSourcer ¶
func NewOptionalFileSourcer(filename string, parser FileParser) Sourcer
NewOptionalFileSourcer creates a file sourcer if the provided file exists. If the provided file is not found, a sourcer is returned returns no values.
func NewTOMLFileSourcer ¶
NewTOMLFileSourcer creates a file sourcer that parses conent as TOML.
func NewYAMLFileSourcer ¶
NewYAMLFileSourcer creates a file sourcer that parses conent as YAML.
type SourcerFlag ¶
type SourcerFlag int
const ( FlagUnknown SourcerFlag = iota FlagFound FlagMissing FlagSkip )