env

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2023 License: MIT Imports: 4 Imported by: 229

Documentation

Overview

Package env implements a koanf.Provider that reads environment variables as conf maps.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Env

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

Env implements an environment variables provider.

func Provider

func Provider(prefix, delim string, cb func(s string) string) *Env

Provider returns an environment variables provider that returns a nested map[string]interface{} of environment variable where the nesting hierarchy of keys is defined by delim. For instance, the delim "." will convert the key `parent.child.key: 1` to `{parent: {child: {key: 1}}}`.

If prefix is specified (case-sensitive), only the env vars with the prefix are captured. cb is an optional callback that takes a string and returns a string (the env variable name) in case transformations have to be applied, for instance, to lowercase everything, strip prefixes and replace _ with . etc. If the callback returns an empty string, the variable will be ignored.

func ProviderWithValue

func ProviderWithValue(prefix, delim string, cb func(key string, value string) (string, interface{})) *Env

ProviderWithValue works exactly the same as Provider except the callback takes a (key, value) with the variable name and value and allows you to modify both. This is useful for cases where you may want to return other types like a string slice instead of just a string.

func (*Env) Read

func (e *Env) Read() (map[string]interface{}, error)

Read reads all available environment variables into a key:value map and returns it.

func (*Env) ReadBytes

func (e *Env) ReadBytes() ([]byte, error)

ReadBytes is not supported by the env provider.

Jump to

Keyboard shortcuts

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