package module
Version: v1.4.0 Latest Latest

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

Go to latest
Published: Apr 22, 2019 License: MIT Imports: 8 Imported by: 1


Go Env



Generate from env file


go get -u github.com/l-vitaly/goenv/cmd/envgen

To generate a config based on the environment variable file, run the following command:

envgen <env_file> <prefix>

  • env_file - environment variable file
  • prefix - this value will be removed from the field names of the structure and constants

You can also group the fields in the structure by separating them with __ characters. For example, if the name of the environment variable is DB__CONN_SRT, then the result will be like this:

type Config {
  Db {
    ConnSrt string




This section is empty.


View Source
var EnvSet = NewEnvSet()

EnvSet env set.


func BoolVar

func BoolVar(p *bool, name string, value bool)

BoolVar load bool.

func DurationVar

func DurationVar(p *time.Duration, name string, value time.Duration)

DurationVar load time.Duration.

func Float64Var

func Float64Var(p *float64, name string, value float64)

Float64Var load float64.

func Int64Var

func Int64Var(p *int64, name string, value int64)

Int64Var load int64.

func IntVar

func IntVar(p *int, name string, value int)

IntVar load int.

func Parse

func Parse()

Parse env.

func StringVar

func StringVar(p *string, name string, value string)

StringVar load string.

func StringsVar

func StringsVar(p *[]string, name string, value []string)

StringsVar load string slice.

func URLVar

func URLVar(p *url.URL, name string, value url.URL)

URLVar load url.

func Uint64Var

func Uint64Var(p *uint64, name string, value uint64)

Uint64Var load uint64.

func UintVar

func UintVar(p *uint, name string, value uint)

UintVar load uint.


type EnvVar

type EnvVar struct {
	Name     string
	Value    Value  // value as set
	DefValue string // default value

EnvVar env var.

type EnvVarSet

type EnvVarSet struct {
	// contains filtered or unexported fields

EnvVarSet envs var set.

func NewEnvSet

func NewEnvSet() *EnvVarSet

NewEnvSet creates a EnvVarSet instance.

func (*EnvVarSet) Parse

func (e *EnvVarSet) Parse() error

Parse env.

func (*EnvVarSet) Var

func (e *EnvVarSet) Var(value Value, name string)

Var load value.

func (*EnvVarSet) VisitAll

func (e *EnvVarSet) VisitAll(fn func(*EnvVar))

VisitAll walk for all envs.

type Value

type Value interface {
	String() string
	Set(string) error

Value env.

Source Files


Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto