cfg
The cfg
package is used to enable the options pattern in Connector.DefineConfig
. This pattern is used in Go for expressing optional arguments. This package defines the various Option
s as well as their collector Config
which is not used directly but rather applies and collects the list of Option
s behind the scenes.
For example:
con.DefineConfig("Database", cfg.Validation("url"), cfg.Secret())
The following options are supported:
cfg.DefaultValue
specifies a default value for the property when one is not provided by the configuratorcfg.Validation
uses a pattern to validate values before they are set
str
- Plain text, no validationstr ^[a-zA-Z0-9]+$
- Text with regexp validationbool
- Must be true
or false
int
- An integer, no validationint [0,60]
- An integer in rangefloat
- A decimal number, no validationfloat [0.0,1.0)
- A decimal number in rangedur
- A duration such as 7h3m45s500ms300us100ns
dur (0s,24h]
- A duration in rangeset Red|Green|Blue
- A set of explicit options separated by |
url
- A URLemail
- An email address, either Joe <joe@example.com>
or just joe@example.com
json
- A valid JSON stringcfg.Secret
indicates that the value of this property is a secret and should not be loggedcfg.Description
is intended to explain the purpose of the config property and how it will impact the microservice