env

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2021 License: MIT Imports: 9 Imported by: 1

README

go-env

Generic environment package to consolidate running variables from OS, parameters, configuration files or other compliant sources

Documentation

Index

Constants

View Source
const (
	ErrVariableAlreadyExists = err.Error("Variable name already exists.")
)

Variables

This section is empty.

Functions

func CmlArgumentsProvider

func CmlArgumentsProvider() *cmlArgumentsProvider

CmlArgumentsProvider Gets the singleton instance for the CML Arguments Provider

func CmlArgumentsSource

func CmlArgumentsSource() *cmlArgumentsSource

func EnvironmentVariablesProvider

func EnvironmentVariablesProvider() *environmentVariablesProvider

EnvironmentVariablesProvider Gets the Environment Variables Provider instance (Singleton)

func EnvironmentVariablesSource

func EnvironmentVariablesSource() *environmentVariablesSource

func FailOnMissingVariables

func FailOnMissingVariables(flag bool)

func Get

func Get(name string) interface{}

Get Gets the value of a variable if it's provided. Returns nil if not.

func JsonConfigurationProvider

func JsonConfigurationProvider() *jsonConfigurationProvider

JsonConfigurationProvider Gets or creates the default JSON configuration Provider instance (Singleton) with default Options

func JsonConfigurationProviderWithOptions

func JsonConfigurationProviderWithOptions(options JsonConfigurationProviderOptions) *jsonConfigurationProvider

JsonConfigurationProviderWithOptions Gets or creates the default JSON Configuration Provider instance (Singleton) with given Options. Options are ignored if there is already a default instance initialized

func JsonConfigurationSource

func JsonConfigurationSource() *jsonConfigurationSource

func Load

func Load() []error

Load initializes environment with provided configuration

func NewJsonConfigurationProviderWithOptions

func NewJsonConfigurationProviderWithOptions(options JsonConfigurationProviderOptions) *jsonConfigurationProvider

NewJsonConfigurationProviderWithOptions Creates a new JSON configuration Provider with given options

func NewYamlConfigurationProvider

func NewYamlConfigurationProvider() *yamlConfigurationProvider

NewYamlConfigurationProvider Creates a new JSON configuration Provider

func NewYamlConfigurationProviderWithOptions

func NewYamlConfigurationProviderWithOptions(options YamlConfigurationProviderOptions) *yamlConfigurationProvider

NewYamlConfigurationProviderWithOptions Creates a new Yaml configuration Provider with given options

func Refresh

func Refresh()

Refresh Refreshes asynchronously. Refresh errors are logged

func SyncedRefresh

func SyncedRefresh() error

SyncedRefresh Refreshes Provider configurations synchronously. A provider does not need to guarantee a refresh, but should have an error-free implementation then.

func Validate

func Validate() error

Validate validates if all non-string properties have been provided by a suitable format

func Var

func Var(name string) *variable

func YamlConfigurationProvider

func YamlConfigurationProvider() *yamlConfigurationProvider

YamlConfigurationProvider Gets or creates the default YAML configuration Provider instance (Singleton) with default Options

func YamlConfigurationProviderWithOptions

func YamlConfigurationProviderWithOptions(options YamlConfigurationProviderOptions) *yamlConfigurationProvider

YamlConfigurationProviderWithOptions Gets or creates the default JSON Configuration Provider instance (Singleton) with given Options. Options are ignored if there is already a default instance initialized

func YamlConfigurationSource

func YamlConfigurationSource() *yamlConfigurationSource

Types

type JsonConfigurationProviderOptions

type JsonConfigurationProviderOptions struct {
	FileFromCml               bool
	CmlSwitch                 string
	CmlPropertyOverride       bool
	CmlPropertyOverrideSwitch string
	Filename                  string
}

type Provider

type Provider interface {
	// Get the value for the given property. nil should be returned if no property is found or an error with it exists
	Get(name string, config interface{}) interface{}

	// Load Loads the values it should provide
	Load() error

	// Refresh the provider sources. Useful for sources which are mutable during a single execution (like file sources)
	// returns a boolean stating if it has newer values and an error for failures. A provider not able to refresh should
	// always return false with no errors.
	Refresh() (bool, error)
}

A Provider is a component that is able to extract values from a specific source, when present. They can be registered in the env package as a source of values

type Settings

type Settings struct {
	FailOnMissingRequired bool
	DefaultSources        []Source
}

type Source

type Source interface {
	// Provider returns the variable provider
	Provider() Provider
	// Config is the provider configuration used to extract the variable from the provider. The returned object should
	// be defined and processed by the provider
	Config() interface{}
}

Source of a variable identifies the provider where the value will come from and the variable configuration to extract the value from the provider

type YamlConfigurationProviderOptions

type YamlConfigurationProviderOptions struct {
	FileFromCml               bool
	CmlSwitch                 string
	CmlPropertyOverride       bool
	CmlPropertyOverrideSwitch string
	Filename                  string
}

Jump to

Keyboard shortcuts

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