Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrNotAStructPtr is returned if you pass something that is not a pointer to a // Struct to Parse ErrNotAStructPtr = errors.New("Expected a pointer to a Struct") // ErrUnsupportedType if the struct field type is not supported by env ErrUnsupportedType = errors.New("Type is not supported") // ErrUnsupportedSliceType if the slice element type is not supported by env ErrUnsupportedSliceType = errors.New("Unsupported slice type") )
Functions ¶
func Parse ¶
func Parse(v 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}
func ParseWithFuncs ¶
func ParseWithFuncs(v interface{}, funcMap CustomParsers) error
ParseWithFuncs is the same as `Parse` except it also allows the user to pass in custom parsers.
Types ¶
type CustomParsers ¶
type CustomParsers map[reflect.Type]ParserFunc
CustomParsers is a friendly name for the type that `ParseWithFuncs()` accepts
type ParserFunc ¶
ParserFunc defines the signature of a function that can be used within `CustomParsers`
Click to show internal directories.
Click to hide internal directories.