envvar

package
v0.0.0-...-b9b7e78 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2018 License: Apache-2.0 Imports: 10 Imported by: 0

README

Env Var Source

The envvar source reads config from environment variables

Format

We expect environment variables to be in the standard format of FOO=bar

Keys are converted to lowercase and split on underscore.

Example
DATABASE_ADDRESS=127.0.0.1
DATABASE_PORT=3306

Becomes

{
    "database": {
        "address": "127.0.0.1",
        "port": 3306
    }
}
Namespace

Env vars can be namespaced so we only have access to a subset

MICRO_DATABASE_ADDRESS=127.0.0.1
MICRO_DATABASE_PORT=3306

The prefix will be trimmed on access

New Source

Specify source with data

envvarSource := envvar.NewSource(
	// optionally specify prefix
	envvar.WithPrefix("MICRO"),
)

Load Source

Load the source into config

// Create new config
conf := config.NewConfig()

// Load file source
conf.Load(envvarSource)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewSource

func NewSource(opts ...source.Option) source.Source

NewSource returns a config source for parsing ENV variables. Underscores are delimiters for nesting, and all keys are lowercased.

Example:

"DATABASE_SERVER_HOST=localhost" will convert to

{
    "database": {
        "server": {
            "host": "localhost"
        }
    }
}

func WithPrefix

func WithPrefix(p string) source.Option

WithPrefix sets the environment variable prefix to scope to. This prefix will be removed from the actual config entries.

Types

This section is empty.

Jump to

Keyboard shortcuts

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