env

package
v1.3.3 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2021 License: MIT Imports: 4 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 are 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.

func (*Env) Watch

func (e *Env) Watch(cb func(event interface{}, err error)) error

Watch is not supported.

Jump to

Keyboard shortcuts

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