github.com/vrischmann/envconfig (go): Package envconfig implements a configuration reader which reads each value from an environment variable.  The basic idea is that you define a configuration struct, like this:  Once you have that, you need to initialize the configuration:  Then it's just a matter of setting the environment variables when calling your binary:  Your conf struct must follow the following rules:  By default, envconfig generates all possible keys based on the field chain according to a flexible naming scheme.  The field chain is how you access your field in the configuration struct. For example:  With that struct, you access the name field via the chain *Shard.Name*  The default naming scheme takes that and transforms it into the following:  It can handles more complicated cases, with multiple words in one field name. It needs to be in the correct case though, for example:  With that struct, you access the name field via the chain *Cassandra.SSLCert* or *Cassandra.SslKey*  The default naming scheme takes that and transforms it into the following:  And, if that is not good enough for you, you always have the option to use a custom key:  Now envconfig will only ever checks the environment variable _cassandraMyName_.  There are three types of content for a single variable:  Example of a valid slice value:  The format for a struct is as follow:  Example of a valid struct value:  Example of a valid slice of struct values:  For bytes slices, you generally don't want to type out a comma-separated list of byte values.  For this use case, we support base64 encoded values.  Here's an example:  This will decode DATA to FOOBAR and put that into conf.Data.  Sometimes you don't absolutely need a value. Here's how we tell envconfig a value is optional:  Sometimes you want a field to be skipped entirely.  Often times you have configuration keys which almost never changes, but you still want to be able to change them.  In such cases, you might want to provide a default value.  Here's to do this with envconfig:  You can of course combine multiple options. The syntax is simple enough, separate each option with a comma.  For example:  This would give you the default timeout of 1 minute, and lookup the myTimeout environment variable.  envconfig supports the following list of types:  Notably, we don't (yet) support complex types simply because I had no use for it yet.  When the standard types are not enough, you will want to use a custom unmarshaler for your types.  You do this by implementing Unmarshaler on your type. Here's an example:
Keywords: configuration|go|golang