env

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2021 License: MIT Imports: 3 Imported by: 6

README

Env

Go Reference

Package env provides helper functions to load environment variables with some degree of control of behavior like: empty, prefixes, default and mutators. All these beneficits come from github.com/sethvargo/go-envconfig.

Documentation

Overview

Package env provides helper functions to load environment variables with some degree of control of behavior like: empty, prefixes, default and mutators. All these beneficits come from github.com/sethvargo/go-envconfig.

Basics:

Define your configuration struct:

type MyConfig struct{
	User     string       `env:"USER,default=facily"`
	Password string       `env:"PASSWORD,required"`
	Timeout time.Duration `env:"TIMEOUT,default=10s"`
}

Somewhere create a instance of MyConfig and call LoadEnv:

var config MyConfig
if err := LoadEnv(ctx, &config, "PREFIX_"); err != nil {
	...
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadEnv

func LoadEnv(ctx context.Context, dst interface{}, prefix string, mutators ...MutatorFunc) error

LoadEnv bring a set of environment variables defined in dst with prefix. Mutators provide a way to change environment variables before defining dst value. We wrap github.com/sethvargo/go-envconfig functionality.

Types

type MutatorFunc

type MutatorFunc func(ctx context.Context, k, v string) (string, error)

MutatorFunc should be used when you want to change environment value before returning for use.

Jump to

Keyboard shortcuts

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