config

package
v2.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 3, 2020 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package config provides a common infrastructure for reading configuration data stored in local TOML files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Read

func Read(path string, dest interface{}) error

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)

SetDuration converts a command line int to a duration, and stores it in the final config.

func SetURL

func SetURL(co *ConfigOption)

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 Horizon to run
	Usage          string              // Help text
	CustomSetValue func(*ConfigOption) // 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) Bind

func (co *ConfigOption) Bind()

Bind binds the config option to viper.

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) SetValue

func (co *ConfigOption) SetValue()

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) SetValues

func (cos ConfigOptions) SetValues()

SetValues calls SetValue on each ConfigOption.

type InvalidConfigError

type InvalidConfigError struct {
	InvalidFields map[string]string
}

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

type TLS

type TLS struct {
	CertificateFile string `toml:"certificate-file" valid:"required"`
	PrivateKeyFile  string `toml:"private-key-file" valid:"required"`
}

TLS represents a common configuration snippet for configuring TLS in a server process

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL