Documentation ¶
Overview ¶
Package config contains helper functions for parsing of configuration files.
Index ¶
Constants ¶
const DirDefault = "."
DirDefault holds a default value "." for flag, which represents current working directory.
const DirFlag = "config-dir"
DirFlag as flag name (see implementation in declareFlags()) is used to define default directory where config files reside. This flag name is derived from the name of the plugin.
const DirUsage = "Location of the configuration files; also set via 'CONFIG_DIR' env variable."
DirUsage used as a flag (see implementation in declareFlags()).
const EnvSuffix = "_CONFIG"
EnvSuffix is added to plugin name while loading plugins configuration from ENV variable.
const FlagSuffix = "-config"
FlagSuffix is added to plugin name while loading plugins configuration.
Variables ¶
This section is empty.
Functions ¶
func Dir ¶ added in v1.0.4
Dir evaluates the flag DirFlag. It interprets "." as current working directory.
func ParseConfigFromYamlFile ¶
ParseConfigFromYamlFile parses a configuration from a file in YAML format. The file's location is specified by the <path> parameter and the resulting config is stored into the structure referenced by the <cfg> parameter. If the file doesn't exist or cannot be read, the returned error will be of type os.PathError. An untyped error is returned in case the file doesn't contain a valid YAML configuration.
func SaveConfigToYamlFile ¶
SaveConfigToYamlFile saves the configuration <cfg> into a YAML-formatted file at the location <path> with permissions defined by <perm>. <comment>, if non-empty, is printed at the beginning of the file before the configuration is printed (with a line break in between). Each line in <comment> should thus begin with the number sign ( # ). If the file cannot be created af the location, os.PathError is returned. An untyped error is returned if the configuration couldn't be marshaled into the YAML format.
Types ¶
type PluginConfig ¶
type PluginConfig interface { // GetValue parses configuration for a plugin and stores the results in data. // The argument data is a pointer to an instance of a go structure. GetValue(data interface{}) (found bool, err error) // GetConfigName returns config name derived from plugin name: // flag = PluginName + FlagSuffix (evaluated most often as absolute path to a config file) GetConfigName() string }
PluginConfig is API for plugins to access configuration.
Aim of this API is to let a particular plugin to bind it's configuration without knowing a particular key name. The key name is injected in flavor (Plugin Name).
func ForPlugin ¶
func ForPlugin(pluginName string, opts ...string) PluginConfig
ForPlugin returns API that is injectable to a particular Plugin and is used to read it's configuration.
It tries to lookup `plugin + "-config"` in flags and declare the flag if it still not exists. It uses the following opts (used to define flag (if it was not already defined)): - default value - usage