Documentation ¶
Overview ¶
Package configparser contains the code required to fill a Go structure representing the configuration information from several sources like:
- a struct containing the default values
- a map from string to strings (e.g. the one that can be extracted for a Kubernetes ConfigMap)
- an environment source like the system environment variables or a "fake" one suitable for testing.
To map the struct fields with the sources, the "env" tag is being used like in the following example:
type Data struct { // WebhookCertDir is the directory where the certificates for the webhooks // need to written. This is different between plain Kubernetes and OpenShift WebhookCertDir string `json:"webhookCertDir" env:"WEBHOOK_CERT_DIR"` // WatchNamespace is the namespace where the operator should watch and // is configurable via environment variables of via the OpenShift console WatchNamespace string `json:"watchNamespace" env:"WATCH_NAMESPACE"` }
The ReadConfigMap function will look for an "WEBHOOK_CERT_DIR" entry inside the passed map or a corresponding environment variable. This function can be used to implement a method in the previous struct like in the following example:
func (config *Data) ReadConfigMap(data map[string]string) { configparser.ReadConfigMap(config, &Data{}, data, configparser.OsEnvironment{}) }
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ReadConfigMap ¶
func ReadConfigMap(target interface{}, defaults interface{}, data map[string]string, env EnvironmentSource)
ReadConfigMap reads the configuration from the environment and the passed in data map. Config and defaults are supposed to be pointers to structs of the same type
Types ¶
type EnvironmentSource ¶
EnvironmentSource is an interface to identify an environment values source.
type OsEnvironment ¶
type OsEnvironment struct{}
OsEnvironment is an EnvironmentSource that fetch data from the OS environment.
func (OsEnvironment) Getenv ¶
func (OsEnvironment) Getenv(key string) string
Getenv retrieves the value of the environment variable named by the key.