Documentation
¶
Overview ¶
Package params is a package to define configuration parameters for servers.
Parameters are defined as tags on structs. Configuration structs might have structs within structs for parameters.
A limited number of data types are supported: strings (string), integers (int, uint), booleans (bool), duration (time.Duration) and floats (float64)
The tags are set with the keyword "param". The fields must be publicly accessible:
type config struct { NameOfApp string `param:"desc=This is the parameter description"` }
Keywords are separated by semicolons. There is no escaping so defaults can't contain equal or semicolons. The following keywords are supported:
desc - a description default - the default value for the parameter min - minimum value for parameter. Flag must be int, uint, float or Duration max - maximum value for parameter. Flag must be int, uint, float or Duration file - if present the flag points to a file and that file must exist. Flag must be a string. required - if present the flag must be specfified in a valid config options - a list of options. Type must be string. Options are case insensitive.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewEnv ¶
func NewEnv(config interface{}) error
NewEnv populates a configuration with values from environment variables.
func NewEnvFlag ¶
NewEnvFlag returns a struct populated with settings from environment variables and command line arguments. The command line arguments overrides the environment variables.
func NewFlag ¶
NewFlag parses the command line parameters. This uses the flag package internally. Flag names are derived from the names in the configuration structures If you have structs within structs the names are prefixed with the name of the structure containing the fields:
type serverConfig struct { HTTP httpConfig // These parameters will be prefixed with http- HostName string // This parameter will be named host-name } type httpConfig struct { Endpoint string // This parameter will be named http-endpoint TLS bool // This parameter will be named http-tls }
Types ¶
This section is empty.