Documentation
¶
Overview ¶
Package configstruct provides a parse function to fill a config struct with values from cli flags or environment
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Parse ¶
func Parse(c interface{}) error
Parse uses a given struct c with tags and parses values from env or cli flags, it uses the default FlagSet and os.Args
Example ¶
Example for using `configstruct` with default values.
// define a struct with tags
type Config struct {
Hostname string `env:"CONFIGSTRUCT_HOSTNAME" cli:"hostname" usage:"hostname value"`
Port int `env:"CONFIGSTRUCT_PORT" cli:"port" usage:"listen port"`
Debug bool `env:"CONFIGSTRUCT_DEBUG" cli:"debug" usage:"debug mode"`
}
// create a variable of the struct type and define defaults if needed
conf := testConfig{
Hostname: "localhost",
Port: 8000,
Debug: true,
}
// now parse values from first cli flags and then env into this var
err := Parse(&conf)
if err != nil {
fmt.Printf("can't parse config %s", err)
}
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.