Documentation ¶
Overview ¶
Package envconfig provides a convenient way to load config from environment variables into a struct using https://github.com/kelseyhightower/envconfig.
Example ¶
package main import ( "time" "github.com/pthethanh/micro/config/envconfig" ) func main() { var conf struct { Name string `envconfig:"NAME" default:"micro"` Address string `envconfig:"ADDRESS" default:"0.0.0.0:8000"` Secret string `envconfig:"SECRET"` Fields []string `envconfig:"FIELDS" default:"field1,field2"` ReadTimeout time.Duration `envconfig:"READ_TIMEOUT" default:"30s"` Enable bool `envconfig:"ENABLE" default:"true"` Map map[string]string `envconfig:"MAP" default:"key:value,key1:value1"` } envconfig.Read(&conf) }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Read ¶
func Read(ptr interface{}, opts ...config.ReadOption) error
Read read configuration from environment to the target ptr.
Example (WithOptions) ¶
package main import ( "github.com/pthethanh/micro/config" "github.com/pthethanh/micro/config/envconfig" ) func main() { var conf struct { Name string `envconfig:"NAME" default:"micro"` Address string `envconfig:"ADDRESS" default:"0.0.0.0:8000"` Secret string `envconfig:"SECRET"` } envconfig.Read(&conf, config.WithPrefix("HTTP")) }
Output:
Types ¶
Click to show internal directories.
Click to hide internal directories.