Skip to content
/ env Public

Env provides a similar interface for environment variables as flag/pflag package

License

Notifications You must be signed in to change notification settings

goph/env

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Env

Build Status Go Report Card GolangCI GoDoc

Env provides a similar interface for environment variables as flag/pflag package.

Usage

The interface follows closely the flag/pflag packages.

package main

import "github.com/goph/env"

func main() {
	// Define environment variables using env.String(), Bool(), Int(), etc.
	var intValue *int = env.Int("int", 1234, "help message for int")
	
	// If you like, you can bind the environment variable to a variable using the Var() functions.
	var intVar int
	env.IntVar(&intVar, "int", 1234, "help message for int")
	
	// Or you can create custom variables that satisfy the Value interface (with pointer receivers)
	// and couple them to variable parsing.
	//
	// For such environment variables, the default value is just the initial value of the variable.
	var intVal env.Value
	env.Var(&intVal, "int", "help message for int")
	
	// After all variables are defined.
	env.Parse()
}

Development

When all coding and testing is done, please run the test suite:

$ make test # go test

For linting we use GolangCI.

$ make lint # golangci-lint run

You can run the whole suite with:

$ make check

License

The MIT License (MIT). Please see License File for more information.

This project is heavily inspired by flag/pflag packages.

About

Env provides a similar interface for environment variables as flag/pflag package

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published