config

package
v0.0.0-...-fb9541f Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2020 License: Apache-2.0 Imports: 15 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
}

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

func (co *ConfigOption) SetValue()

SetValue sets a value in the global config, using a custom function, if one was provided.

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