Documentation ¶
Overview ¶
Package config provides a common infrastructure for reading configuration data stored in local TOML files.
Index ¶
- func IsExplicitlySet(co *ConfigOption) bool
- func Read(path string, dest interface{}) error
- func SetDuration(co *ConfigOption) error
- func SetOptionalString(co *ConfigOption) error
- func SetOptionalUint(co *ConfigOption) error
- func SetURL(co *ConfigOption) error
- func Validate(dest interface{}) error
- type ConfigOption
- type ConfigOptions
- type InvalidConfigError
- type TLS
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsExplicitlySet ¶
func IsExplicitlySet(co *ConfigOption) bool
IsExplicitlySet returns true if and only if the given config option was set explicitly either via a command line argument or via an environment variable
func Read ¶
Read takes the TOML configuration file at `path`, parses it into `dest` and then uses github.com/asaskevich/govalidator to validate the struct.
func SetDuration ¶
func SetDuration(co *ConfigOption) error
SetDuration converts a command line int to a duration, and stores it in the final config.
func SetOptionalString ¶
func SetOptionalString(co *ConfigOption) error
SetOptionalString converts a command line uint to a *string where the nil value indicates the flag was not explicitly set
func SetOptionalUint ¶
func SetOptionalUint(co *ConfigOption) error
SetOptionalUint converts a command line uint to a *uint where the nil value indicates the flag was not explicitly set
func SetURL ¶
func SetURL(co *ConfigOption) error
SetURL converts a command line string to a URL, and stores it in the final config.
Types ¶
type ConfigOption ¶
type ConfigOption struct { Name string // e.g. "db-url" EnvVar string // e.g. "DATABASE_URL". Defaults to uppercase/underscore representation of name OptType types.BasicKind // The type of this option, e.g. types.Bool FlagDefault interface{} // A default if no option is provided. Omit or set to `nil` if no default Required bool // Whether this option must be set for Frontier to run Usage string // Help text CustomSetValue func(*ConfigOption) error // Optional function for custom validation/transformation ConfigKey interface{} // Pointer to the final key in the linked Config struct // contains filtered or unexported fields }
ConfigOption is a complete description of the configuration of a command line option
func (*ConfigOption) Init ¶
func (co *ConfigOption) Init(cmd *cobra.Command) error
Init handles initialisation steps, including configuring and binding the env variable name.
func (*ConfigOption) Require ¶
func (co *ConfigOption) Require()
Require checks that a required string configuration option is not empty, raising a user error if it is.
func (*ConfigOption) RequireE ¶
func (co *ConfigOption) RequireE() error
RequireE is like Require, but returns the error instead of Fatal
func (*ConfigOption) SetValue ¶
func (co *ConfigOption) SetValue() error
SetValue sets a value in the global config, using a custom function, if one was provided.
func (*ConfigOption) UsageText ¶
func (co *ConfigOption) UsageText() string
UsageText returns the string to use for the usage text of the option. The string returned will be the Usage defined on the ConfigOption, along with the environment variable.
type ConfigOptions ¶
type ConfigOptions []*ConfigOption
ConfigOptions is a group of ConfigOptions that can be for convenience initialized and set at the same time.
func (ConfigOptions) Init ¶
func (cos ConfigOptions) Init(cmd *cobra.Command) error
Init calls Init on each ConfigOption passing on the cobra.Command.
func (ConfigOptions) Require ¶
func (cos ConfigOptions) Require()
Require calls Require on each ConfigOption.
func (ConfigOptions) RequireE ¶
func (cos ConfigOptions) RequireE() error
RequireE is like Require, but returns the error instead of Fatal
func (ConfigOptions) SetValues ¶
func (cos ConfigOptions) SetValues() error
SetValues calls SetValue on each ConfigOption.
type InvalidConfigError ¶
InvalidConfigError is the error that is returned when an invalid configuration is encountered by the `Read` func.
func (*InvalidConfigError) Error ¶
func (err *InvalidConfigError) Error() string