configloader

package
v0.17.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 20, 2023 License: MIT Imports: 13 Imported by: 0

README

configloaded

Installation

go get github.com/effective-security/porto/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.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAbsFilename

func GetAbsFilename(file, projFolder string) (string, error)

GetAbsFilename returns absolute path for the file from the relative path to projFolder

Types

type Factory

type Factory struct {
	// contains filtered or unexported fields
}

Factory is used to create Configuration instance

func NewFactory

func NewFactory(nodeInfo netutil.NodeInfo, searchDirs []string, envPrefix string) (*Factory, error)

NewFactory returns new configuration factory

func (*Factory) Load

func (f *Factory) Load(configFile string, config interface{}) (absConfigFile string, err error)

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 interface{}) (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

func (f *Factory) ResolveConfigFile(configFile string) (absConfigFile, baseDir string, err error)

ResolveConfigFile returns absolute path for the config file

func (*Factory) WithEnvironment

func (f *Factory) WithEnvironment(environment string) *Factory

WithEnvironment allows to override environment in Configuration

func (*Factory) WithOverride

func (f *Factory) WithOverride(file string) *Factory

WithOverride allows to specify additional override config file

type Hostmap

type Hostmap struct {
	// Override is a map of host name to file location
	Override map[string]string
}

Hostmap provides overrides info

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL