package
0.6.41
Repository: https://github.com/effective-security/x.git
Documentation: pkg.go.dev

# README

configloaded

Installation

go get github.com/effective-security/x/pkg/configloader

Usage

	f, err := NewFactory(nil, []string{"/cfg/override_location"}, "MYSERVICE_")
	if err != nil {
        return err
    }

	var c configuration
	err = f.Load(cfgFile, &c)
	if err != nil {
        return err
    }

Environment variables

The loader interpolates configuration values with the supported environment variables described below, and other OS Env variables that has prefix passed to NewFactory

  • ${HOSTNAME} : host name
  • ${NODENAME} : node name if the cluster
  • ${LOCALIP} : local IP address
  • ${USER} : user name under which the process is running
  • ${NORMALIZED_USER} : user name without dots
  • ${ENVIRONMENT} : environment name of the deployment, aka test,dev,prod etc
  • ${ENVIRONMENT_UPPERCASE} : environment name in upper case
  • any environment variable started with MYSERVICE_ prefix

Config override

The loader supports config overrides by host name, or with a provided file by WithOverride method.

If there is file named as the config file with .hostmap suffix, if will be loaded, and override values will be applied to the main config file, based on the host name.

The format of the .hostmap file:

override:
  HOSTNAME: override.yaml

See testdata folder for examples.

# Functions

ExpandAll replace variables in the input object, using default Expander.
GetAbsFilename returns absolute path for the file from the relative path to projFolder.
Marshal saves object to file.
NewFactory returns new configuration factory.
ResolveValue returns value loaded from file:// or env:// If val does not start with file:// or env://, then the value is returned as is.
ResolveValue returns value loaded from file:// or env:// If val does not start with file:// or env://, then the value is returned as is.
Unmarshal JSON or YAML file to an interface.
UnmarshalAndExpand load JSON or YAML file to an interface and expands variables.

# Constants

EnvSource specifies to load config from an environment variable.
FileSource specifies to load config from a file.
SecretSource specifies to load config from a secret manager.

# Variables

SecretProviderInstance is a global instance of SecretLoader.

# Structs

Expander is used to expand variables in the input object.
Factory is used to create Configuration instance.
Hostmap provides overrides info.

# Interfaces

SecretProvider is an interface to provide secrets.