A convenient way to read environment variable.
-
go get github.com/woohaha/envUnmarshal-go
-
Define struct
type Param struct {
First string `env:"first"`
Second string `env:"second"`
Third string `env:"third"`
}
Note: Type of Fields must be
string
- Declare an object of the struct
var param *Param
- Inject environment variables into object
import env "github.com/woohaha/envUnmarshal-go"
env.Unmarshal(param)
- Enjoy
fmt.Println(param.First)