package
Version:
v1.3.1
Opens a new window with list of versions in this module.
Published: Jul 19, 2021
License: MIT
Opens a new window with license information.
Imports: 2
Opens a new window with list of imports.
Imported by: 3
Opens a new window with list of known importers.
README
¶
Env
Get the machine's enviroment variables if they exist
Usage
In this example we overwrite the toml settings with the enviroment settings
func main() {
c := config{}
if err := toml.Unmarshal(file, &c); err != nil {
panic(err)
}
if err := env.Unmarshal(&c); err != nil {
panic(err)
}
setupWebContext(c)
}
type config struct {
Cors []string `toml:"cors" env:"WEB_CORS"`
DB dbConfig `toml:"db"`
}
type dbConfig struct {
Driver string `toml:"driver" env:"DB_DRIVER"`
Connection string `toml:"connection_string" env:"DB_STRING"`
}
Documentation
¶
Package env is for parsing environment variables.
Usage ¶
Create a struct that requires an environment variable and parse:
type dbConfig struct {
ConnectionString string `toml:"connection_string" env:"DB_CONNECTION_STRING"`
Driver string `toml:"driver" env:"DB_DRIVER"`
}
func main() {
conf := new(dbConfig)
if err := env.Parse(conf); err != nil {
...
func Parse(obj interface{}) error
Parse reads the object and sets the properties to
Source Files
¶
Click to show internal directories.
Click to hide internal directories.