Skip to content
Golang handling of environment values
Go
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
example/simple
.gitignore
.travis.yml
LICENSE
README.md
bool.go
bool_test.go
bytes.go
bytes_test.go
duration.go
duration_test.go
error.go
field.go
go.mod
go.sum
int.go
int_test.go
ints.go
ints_test.go
options.go
print.go
print_flag.go
print_test.go
string.go
string_test.go
strings.go
strings_test.go

README.md

env

GoDoc Build Status

Implements a simple way of handling environment values. Each environment field is simply reflected by a variable inside the Go program. Out of the box handlers for the types bool, []byte, time.Duration, int, []int, string and []string are provided. Other types can be added by using the RegisterField function.

Example

var (
	name = env.String("NAME", "joe")
	age  = env.Int("AGE", 24)
)

func main() {
	env.ParseFlags()

	fmt.Printf("%s is %d years old\n", name.Get(), age.Get())
}

If the program is called with -print short-bash, all registered environment fields would be printed...

NAME="joe"
AGE="24"

By using -print long-bash, a description for each field is generated.

# String field. The default value is 'joe'.
NAME="joe"

# Int field. The default value is '24'.
AGE="24"

License

The project is licensed under Apache 2.0.

You can’t perform that action at this time.