Documentation ¶
Overview ¶
The Tideland Go Library configuration package provides the reading, parsing, and accessing of configuration data. Different readers can be passed as sources for the SML formatted input. The retrieved value at a given path can be checked for an error or directly used as input for stringex.Defaulter.
Index ¶
Constants ¶
const ( ErrIllegalSourceFormat = iota + 1 ErrIllegalConfigSource ErrCannotReadFile ErrInvalidPath ErrCannotApply )
Variables ¶
This section is empty.
Functions ¶
func IsInvalidPathError ¶
IsInvalidPathError checks if a path cannot be found.
func PackageVersion ¶
PackageVersion returns the version of the version package.
Types ¶
type Configuration ¶
type Configuration interface { // At retrieves the value at a given path. At(path ...string) Value // Apply creates a new configuration by adding of overwriting // the passed values. The keys of the map have to be slash // separated configuration paths without the leading "config". Apply(kvs map[string]string) (Configuration, error) }
Configuration contains the read configuration and provides typed access to it. The root node "config" is automatically preceded to the path.
func Read ¶
func Read(source io.Reader) (Configuration, error)
Read reads the SML source of the configuration from a reader, parses it, and returns the configuration instance.
func ReadFile ¶
func ReadFile(filename string) (Configuration, error)
ReadFile reads the SML source of a configuration file, parses it, and returns the configuration instance.
func ReadString ¶
func ReadString(source string) (Configuration, error)
ReadString reads the SML source of the configuration from a string, parses it, and returns the configuration instance.
type Value ¶
type Value interface { // List returns the configuration keys below the value. List() ([]string, error) // Value returns the value as string. Value() (string, error) // Error returns the error if the value retrieval fails. Error() error }
Value contains the found string value at a given path or an error if the path is invalid. A convenient converting can be done using the stringex.Defaulter. So e.g. accessing a configuration and interpret it as int woud be
myInt := myDefaulter.AsInt(myConfig.At("path", "to", "value"), 42)
An error check can also be done by myValue.Error().