Documentation
¶
Index ¶
- func Gather(opts ReadOptions, out interface{}) error
- type ReadOptions
- func (ro ReadOptions) EnvDefault() ReadOptions
- func (ro ReadOptions) SetArg(arg string, fieldPath string) ReadOptions
- func (ro ReadOptions) SetArgsFileOverride(args ...string) ReadOptions
- func (ro ReadOptions) SetArgsMap(argsMap map[string]string, rewrite ...bool) ReadOptions
- func (ro ReadOptions) SetBasePath(path string) ReadOptions
- func (ro ReadOptions) SetDefaultsMap(defMap map[string]interface{}, rewrite ...bool) ReadOptions
- func (ro ReadOptions) SetEnvOverride(vars ...string) ReadOptions
- func (ro ReadOptions) SetEnvSearchPaths(paths ...string) ReadOptions
- func (ro ReadOptions) SetEnvSearchPattern(pattern string) ReadOptions
- func (ro ReadOptions) SetVar(v string, fieldPath string) ReadOptions
- func (ro ReadOptions) SetVarsMap(varsMap map[string]string, rewrite ...bool) ReadOptions
- type SettingsError
- func SettingsFieldDoesNotExist(overrideType string, fieldName string) SettingsError
- func SettingsFieldSetError(fieldName string, t reflect.Kind, m ...error) SettingsError
- func SettingsFieldTypeMismatch(fieldName string, expectedType reflect.Kind, receivedType reflect.Kind) SettingsError
- func SettingsFileParseError(path string, desc string) SettingsError
- func SettingsFileReadError(path string, desc string) SettingsError
- func SettingsFileTypeError(path string, ext string) SettingsError
- func SettingsOutCannotBeNil() SettingsError
- func SettingsTypeDiscoveryError(t reflect.Kind) SettingsError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Gather ¶
func Gather(opts ReadOptions, out interface{}) error
Gather compiles configuration from various sources and iteratively builds up the out object with the values that are retrieved successively from the following sources: 1. base settings file 2. defaults as configured in options (*diverges from github.com/brozeph/settings-lib) 3. override files (from command line) 4. override files (from environment) 5. command line arguments 6. environment variables
Types ¶
type ReadOptions ¶
type ReadOptions struct { ArgsFileOverride []string ArgsMap map[string]string BasePath string DefaultsMap map[string]interface{} EnvOverride []string EnvSearchPaths []string EnvSearchPattern string VarsMap map[string]string }
ReadOptions define additional optional instructions for the Settings package when reading and compiling layers of configuration settings from various sources
func Options ¶
func Options() ReadOptions
Options returns an empty ReadOptions for use with the Settings package
func (ReadOptions) EnvDefault ¶ added in v1.1.0
func (ro ReadOptions) EnvDefault() ReadOptions
EnvDefault populates the ReadOptions struct with a a default environment override variable setting and a few default search paths
func (ReadOptions) SetArg ¶ added in v1.1.0
func (ro ReadOptions) SetArg(arg string, fieldPath string) ReadOptions
SetArg can be used to explicitly map a command line argument to a field
func (ReadOptions) SetArgsFileOverride ¶
func (ro ReadOptions) SetArgsFileOverride(args ...string) ReadOptions
SetArgsFileOverride instructs the settings package on where to look for any potential override file locations that are provided as command line arguments
func (ReadOptions) SetArgsMap ¶
func (ro ReadOptions) SetArgsMap(argsMap map[string]string, rewrite ...bool) ReadOptions
SetArgsMap will either rewrite or, by default, augment the map that defines which configuration keys are related to the specified command line arguments
func (ReadOptions) SetBasePath ¶
func (ro ReadOptions) SetBasePath(path string) ReadOptions
SetBasePath can be used to define the path to the base settings file which is the first element loaded when the Settings package begins reading configuration
func (ReadOptions) SetDefaultsMap ¶
func (ro ReadOptions) SetDefaultsMap(defMap map[string]interface{}, rewrite ...bool) ReadOptions
SetDefaultsMap can be used to define default values for config elements in the event that the value is not provided in one of the layered mechanisms used to read settings
func (ReadOptions) SetEnvOverride ¶
func (ro ReadOptions) SetEnvOverride(vars ...string) ReadOptions
SetEnvOverride instructs the settings package on where to look for any potential override file locations that are provided as environment variables to the application
func (ReadOptions) SetEnvSearchPaths ¶
func (ro ReadOptions) SetEnvSearchPaths(paths ...string) ReadOptions
SetEnvSearchPaths can be used to instruct the Settings package on where it might find additional configuration files for use when loading additional layers of configuration
func (ReadOptions) SetEnvSearchPattern ¶ added in v1.2.0
func (ro ReadOptions) SetEnvSearchPattern(pattern string) ReadOptions
func (ReadOptions) SetVar ¶ added in v1.1.0
func (ro ReadOptions) SetVar(v string, fieldPath string) ReadOptions
SetVar can be used to explicitly map an environment variable to a field
func (ReadOptions) SetVarsMap ¶
func (ro ReadOptions) SetVarsMap(varsMap map[string]string, rewrite ...bool) ReadOptions
SetVarsMap will either rewrite or, by default, augment the map that associates environment variables to various configuration keys specified in the base
type SettingsError ¶
type SettingsError struct {
Message string
}
SettingsError is any type of error that is raised specifically related to gathering and applying settings from each of the specified sources
func SettingsFieldDoesNotExist ¶
func SettingsFieldDoesNotExist(overrideType string, fieldName string) SettingsError
SettingsFieldDoesNotExist is an error when a field is specified via the DefaultsMap that does not exist in the out struct value that is provided to settings.Gather
func SettingsFieldSetError ¶
func SettingsFieldSetError(fieldName string, t reflect.Kind, m ...error) SettingsError
SettingsFieldSetError is raised when a field's value is not actually settable
func SettingsFieldTypeMismatch ¶
func SettingsFieldTypeMismatch(fieldName string, expectedType reflect.Kind, receivedType reflect.Kind) SettingsError
SettingsFieldTypeMismatch is raised in the event there is a mismatch between types when trying to override a specific value
func SettingsFileParseError ¶
func SettingsFileParseError(path string, desc string) SettingsError
SettingsFileParseError occurs when a specified settings file can't be properly unmarshalled
func SettingsFileReadError ¶
func SettingsFileReadError(path string, desc string) SettingsError
SettingsFileReadError occurs when a specified settings file is not readable
func SettingsFileTypeError ¶
func SettingsFileTypeError(path string, ext string) SettingsError
SettingsFileTypeError occurs when a format is requested that the settings package does not support
func SettingsOutCannotBeNil ¶
func SettingsOutCannotBeNil() SettingsError
SettingsOutCannotBeNil occurs when the out field in the settings struct is set to nil, intentionally or otherwise
func SettingsTypeDiscoveryError ¶
func SettingsTypeDiscoveryError(t reflect.Kind) SettingsError
SettingsTypeDiscoveryError occurs when the out value provided to settings.Gather is not a struct
func (SettingsError) Error ¶
func (e SettingsError) Error() string
Directories
¶
Path | Synopsis |
---|---|
package main in the example can be used to demo the settings parsing from command line, environment variables, specified override files and environment overrides.
|
package main in the example can be used to demo the settings parsing from command line, environment variables, specified override files and environment overrides. |