Documentation
¶
Overview ¶
Package configloader loads JSON/YAML config with environment overrides.
Index ¶
- Constants
- func ExpandAll(obj any) error
- func GetAbsFilename(file, projFolder string) (string, error)
- func Marshal(fn string, value any) error
- func ResolveValue(val string) (string, error)
- func ResolveValueWithSecrets(val string, loader SecretProvider) (string, error)
- func Unmarshal(file string, v any) error
- func UnmarshalAndExpand(file string, v any) error
- type Expander
- type Factory
- func (f *Factory) Load(configFile string, config any) (absConfigFile string, err error)
- func (f *Factory) LoadForHostName(configFile, hostnameOverride string, config any) (absConfigFile string, err error)
- func (f *Factory) ResolveConfigFile(configFile string) (absConfigFile, baseDir string, err error)
- func (f *Factory) WithEnvironment(environment string) *Factory
- func (f *Factory) WithOverride(file string) *Factory
- func (f *Factory) WithSecretProvider(p SecretProvider) *Factory
- type Hostmap
- type SecretProvider
Constants ¶
const ( // FileSource specifies to load config from a file FileSource = "file://" // EnvSource specifies to load config from an environment variable EnvSource = "env://" // SecretSource specifies to load config from a secret manager SecretSource = "secret://" )
Variables ¶
This section is empty.
Functions ¶
func ExpandAll ¶
ExpandAll replace variables in the input object, using default Expander. The input object must be a pointer to a struct. If secrets are used, SecretProviderInstance must be set. The values started with env:// , file:// or secret:// must be resolved. The values inside ${} will be tried to be resolved, if not found will be substiduted with empy values as per os.Getenv function.
func GetAbsFilename ¶
GetAbsFilename returns absolute path for the file from the relative path to projFolder
func ResolveValue ¶
ResolveValue returns value loaded from file:// or env:// If val does not start with file:// or env://, then the value is returned as is
func ResolveValueWithSecrets ¶
func ResolveValueWithSecrets(val string, loader SecretProvider) (string, error)
ResolveValue returns value loaded from file:// or env:// If val does not start with file:// or env://, then the value is returned as is
func UnmarshalAndExpand ¶
UnmarshalAndExpand load JSON or YAML file to an interface and expands variables
Types ¶
type Expander ¶
type Expander struct {
Variables map[string]string
SecretProvider SecretProvider
}
Expander is used to expand variables in the input object
type Factory ¶
type Factory struct {
// contains filtered or unexported fields
}
Factory is used to create Configuration instance
func NewFactory ¶
NewFactory returns new configuration factory
func (*Factory) Load ¶
Load will load the configuration from the named config file, apply any overrides, and resolve relative directory locations.
func (*Factory) LoadForHostName ¶
func (f *Factory) LoadForHostName(configFile, hostnameOverride string, config any) (absConfigFile string, err error)
LoadForHostName will load the configuration from the named config file for specified host name, apply any overrides, and resolve relative directory locations.
func (*Factory) ResolveConfigFile ¶
ResolveConfigFile returns absolute path for the config file
func (*Factory) WithEnvironment ¶
WithEnvironment allows to override environment in Configuration
func (*Factory) WithOverride ¶
WithOverride allows to specify additional override config file
func (*Factory) WithSecretProvider ¶
func (f *Factory) WithSecretProvider(p SecretProvider) *Factory
WithSecretProvider allows to specify secret provider
type Hostmap ¶
type Hostmap struct {
// Override is a map of host name to file location
Override map[string]string
}
Hostmap provides overrides info
type SecretProvider ¶
SecretProvider is an interface to provide secrets
var SecretProviderInstance SecretProvider
SecretProviderInstance is a global instance of SecretLoader