Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrNotAStructPtr = errors.New("Expected a pointer to a Struct")
ErrNotAStructPtr is returned if you pass something that is not a pointer to a Struct to Parse
View Source
var ErrUnsupportedSliceType = errors.New("Unsupported slice type")
ErrUnsupportedSliceType if the slice element type is not supported by env
View Source
var ErrUnsupportedType = errors.New("Type is not supported")
ErrUnsupportedType if the struct field type is not supported by env
Functions ¶
func Parse ¶
func Parse(val interface{}) error
Parse parses a struct containing `env` tags and loads its values from environment variables.
Example ¶
package main
import (
"fmt"
"os"
"github.com/caarlos0/env"
)
func main() {
type config struct {
Home string `env:"HOME"`
Port int `env:"PORT" envDefault:"3000"`
IsProduction bool `env:"PRODUCTION"`
}
os.Setenv("HOME", "/tmp/fakehome")
cfg := config{}
env.Parse(&cfg)
fmt.Println(cfg)
}
Output: {/tmp/fakehome 3000 false}
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.