config

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2018 License: MPL-2.0 Imports: 18 Imported by: 3

Documentation

Index

Constants

View Source
const (
	// DefaultLogLevel is the default logging level.
	DefaultLogLevel = "WARN"

	// DefaultMaxStale is the default staleness permitted. This enables stale
	// queries by default for performance reasons.
	DefaultMaxStale = 2 * time.Second

	// DefaultReloadSignal is the default signal for reload.
	DefaultReloadSignal = syscall.SIGHUP

	// DefaultKillSignal is the default signal for termination.
	DefaultKillSignal = syscall.SIGINT
)
View Source
const (
	// DefaultRetryAttempts is the default number of maximum retry attempts.
	DefaultRetryAttempts = 12

	// DefaultRetryBackoff is the default base for the exponential backoff
	// algorithm.
	DefaultRetryBackoff = 250 * time.Millisecond

	// DefaultRetryMaxBackoff is the default maximum of backoff time
	DefaultRetryMaxBackoff = 1 * time.Minute
)
View Source
const (
	// DefaultDialKeepAlive is the default amount of time to keep alive
	// connections.
	DefaultDialKeepAlive = 30 * time.Second

	// DefaultDialTimeout is the amount of time to attempt to dial before timing
	// out.
	DefaultDialTimeout = 30 * time.Second

	// DefaultIdleConnTimeout is the default connection timeout for idle
	// connections.
	DefaultIdleConnTimeout = 90 * time.Second

	// DefaultMaxIdleConns is the default number of maximum idle connections.
	DefaultMaxIdleConns = 100

	// DefaultTLSHandshakeTimeout is the amount of time to negotiate the TLS
	// handshake.
	DefaultTLSHandshakeTimeout = 10 * time.Second
)
View Source
const (
	// DefaultSSLVerify is the default value for SSL verification.
	DefaultSSLVerify = true
)
View Source
const (
	// DefaultSyslogFacility is the default facility to log to.
	DefaultSyslogFacility = "LOCAL0"
)

Variables

View Source
var (
	// DefaultMaxIdleConnsPerHost is the default number of idle connections to use
	// per host.
	DefaultMaxIdleConnsPerHost = runtime.GOMAXPROCS(0) + 1
)
View Source
var (
	// ErrAuthStringEmpty is the error returned with authentication is provided,
	// but empty.
	ErrAuthStringEmpty = errors.New("auth: cannot be empty")
)

Functions

func Bool

func Bool(b bool) *bool

Bool returns a pointer to the given bool.

func BoolGoString

func BoolGoString(b *bool) string

BoolGoString returns the value of the boolean for printing in a string.

func BoolPresent

func BoolPresent(b *bool) bool

BoolPresent returns a boolean indicating if the pointer is nil, or if the pointer is pointing to the zero value..

func BoolVal

func BoolVal(b *bool) bool

BoolVal returns the value of the boolean at the pointer, or false if the pointer is nil.

func ConsulStringToStructFunc

func ConsulStringToStructFunc() mapstructure.DecodeHookFunc

ConsulStringToStructFunc checks if the value set for the key should actually be a struct and sets the appropriate value in the struct. This is for backwards-compatability with older versions of Consul Template.

func FileMode

func FileMode(o os.FileMode) *os.FileMode

FileMode returns a pointer to the given os.FileMode.

func FileModeGoString

func FileModeGoString(o *os.FileMode) string

FileModeGoString returns the value of the os.FileMode for printing in a string.

func FileModePresent

func FileModePresent(o *os.FileMode) bool

FileModePresent returns a boolean indicating if the pointer is nil, or if the pointer is pointing to the zero value.

func FileModeVal

func FileModeVal(o *os.FileMode) os.FileMode

FileModeVal returns the value of the os.FileMode at the pointer, or 0 if the pointer is nil.

func Int

func Int(i int) *int

Int returns a pointer to the given int.

func IntGoString

func IntGoString(i *int) string

IntGoString returns the value of the int for printing in a string.

func IntPresent

func IntPresent(i *int) bool

IntPresent returns a boolean indicating if the pointer is nil, or if the pointer is pointing to the zero value.

func IntVal

func IntVal(i *int) int

IntVal returns the value of the int at the pointer, or 0 if the pointer is nil.

func Signal

func Signal(s os.Signal) *os.Signal

Signal returns a pointer to the given os.Signal.

func SignalGoString

func SignalGoString(s *os.Signal) string

SignalGoString returns the value of the os.Signal for printing in a string.

func SignalPresent

func SignalPresent(s *os.Signal) bool

SignalPresent returns a boolean indicating if the pointer is nil, or if the pointer is pointing to the zero value..

func SignalVal

func SignalVal(s *os.Signal) os.Signal

SignalVal returns the value of the os.Signal at the pointer, or 0 if the pointer is nil.

func String

func String(s string) *string

String returns a pointer to the given string.

func StringGoString

func StringGoString(s *string) string

StringGoString returns the value of the string for printing in a string.

func StringPresent

func StringPresent(s *string) bool

StringPresent returns a boolean indicating if the pointer is nil, or if the pointer is pointing to the zero value..

func StringToFileModeFunc

func StringToFileModeFunc() mapstructure.DecodeHookFunc

StringToFileModeFunc returns a function that converts strings to os.FileMode value. This is designed to be used with mapstructure for parsing out a filemode value.

func StringVal

func StringVal(s *string) string

StringVal returns the value of the string at the pointer, or "" if the pointer is nil.

func TimeDuration

func TimeDuration(t time.Duration) *time.Duration

TimeDuration returns a pointer to the given time.Duration.

func TimeDurationGoString

func TimeDurationGoString(t *time.Duration) string

TimeDurationGoString returns the value of the time.Duration for printing in a string.

func TimeDurationPresent

func TimeDurationPresent(t *time.Duration) bool

TimeDurationPresent returns a boolean indicating if the pointer is nil, or if the pointer is pointing to the zero value..

func TimeDurationVal

func TimeDurationVal(t *time.Duration) time.Duration

TimeDurationVal returns the value of the string at the pointer, or 0 if the pointer is nil.

Types

type AuthConfig

type AuthConfig struct {
	Enabled  *bool   `mapstructure:"enabled"`
	Username *string `mapstructure:"username"`
	Password *string `mapstructure:"password"`
}

AuthConfig is the HTTP basic authentication data.

func DefaultAuthConfig

func DefaultAuthConfig() *AuthConfig

DefaultAuthConfig is the default configuration.

func ParseAuthConfig

func ParseAuthConfig(s string) (*AuthConfig, error)

ParseAuthConfig parses the auth into username:password.

func (*AuthConfig) Copy

func (c *AuthConfig) Copy() *AuthConfig

Copy returns a deep copy of this configuration.

func (*AuthConfig) Finalize

func (c *AuthConfig) Finalize()

Finalize ensures there no nil pointers.

func (*AuthConfig) GoString

func (c *AuthConfig) GoString() string

GoString defines the printable version of this struct.

func (*AuthConfig) Merge

func (c *AuthConfig) Merge(o *AuthConfig) *AuthConfig

Merge combines all values in this configuration with the values in the other configuration, with values in the other configuration taking precedence. Maps and slices are merged, most other values are overwritten. Complex structs define their own merge functionality.

func (*AuthConfig) String

func (c *AuthConfig) String() string

String is the string representation of this authentication. If authentication is not enabled, this returns the empty string. The username and password will be separated by a colon.

type Config

type Config struct {
	// Consul is the configuration for connecting to a Consul cluster.
	Consul *ConsulConfig `mapstructure:"consul"`

	// KillSignal is the signal to listen for a graceful terminate event.
	KillSignal *os.Signal `mapstructure:"kill_signal"`

	// LogLevel is the level with which to log for this config.
	LogLevel *string `mapstructure:"log_level"`

	// PidFile is the path on disk where a PID file should be written containing
	// this processes PID.
	PidFile *string `mapstructure:"pid_file"`

	// ReloadSignal is the signal to listen for a reload event.
	ReloadSignal *os.Signal `mapstructure:"reload_signal"`

	// Syslog is the configuration for syslog.
	Syslog *SyslogConfig `mapstructure:"syslog"`

	From *string `mapstructure:"from"`

	To *string `mapstructure:"to"`

	Interval *time.Duration `mapstructure:"interval"`
}

Config is used to configure Consul Template

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns the default configuration struct. Certain environment variables may be set which control the values for the default configuration.

func FromFile

func FromFile(path string) (*Config, error)

FromFile reads the configuration file at the given path and returns a new Config struct with the data populated.

func FromPath

func FromPath(path string) (*Config, error)

FromPath iterates and merges all configuration files in a given directory, returning the resulting config.

func Must

func Must(s string) *Config

Must returns a config object that must compile. If there are any errors, this function will panic. This is most useful in testing or constants.

func Parse

func Parse(s string) (*Config, error)

Parse parses the given string contents as a config

func TestConfig

func TestConfig(c *Config) *Config

TestConfig returns a default, finalized config, with the provided configuration taking precedence.

func (*Config) Copy

func (c *Config) Copy() *Config

Copy returns a deep copy of the current configuration. This is useful because the nested data structures may be shared.

func (*Config) Finalize

func (c *Config) Finalize()

Finalize ensures all configuration options have the default values, so it is safe to dereference the pointers later down the line. It also intelligently tries to activate stanzas that should be "enabled" because data was given, but the user did not explicitly add "Enabled: true" to the configuration.

func (*Config) GoString

func (c *Config) GoString() string

GoString defines the printable version of this struct.

func (*Config) Merge

func (c *Config) Merge(o *Config) *Config

Merge merges the values in config into this config object. Values in the config object overwrite the values in c.

type ConsulConfig

type ConsulConfig struct {
	// Address is the address of the Consul server. It may be an IP or FQDN.
	Address *string

	// Auth is the HTTP basic authentication for communicating with Consul.
	Auth *AuthConfig `mapstructure:"auth"`

	// Retry is the configuration for specifying how to behave on failure.
	Retry *RetryConfig `mapstructure:"retry"`

	// SSL indicates we should use a secure connection while talking to
	// Consul. This requires Consul to be configured to serve HTTPS.
	SSL *SSLConfig `mapstructure:"ssl"`

	// Token is the token to communicate with Consul securely.
	Token *string

	// Transport configures the low-level network connection details.
	Transport *TransportConfig `mapstructure:"transport"`
}

ConsulConfig contains the configurations options for connecting to a Consul cluster.

func DefaultConsulConfig

func DefaultConsulConfig() *ConsulConfig

DefaultConsulConfig returns a configuration that is populated with the default values.

func (*ConsulConfig) Copy

func (c *ConsulConfig) Copy() *ConsulConfig

Copy returns a deep copy of this configuration.

func (*ConsulConfig) Finalize

func (c *ConsulConfig) Finalize()

Finalize ensures there no nil pointers.

func (*ConsulConfig) GoString

func (c *ConsulConfig) GoString() string

GoString defines the printable version of this struct.

func (*ConsulConfig) Merge

func (c *ConsulConfig) Merge(o *ConsulConfig) *ConsulConfig

Merge combines all values in this configuration with the values in the other configuration, with values in the other configuration taking precedence. Maps and slices are merged, most other values are overwritten. Complex structs define their own merge functionality.

type EnvConfig

type EnvConfig struct {
	// BlacklistEnv specifies a list of environment variables to explicitly
	// exclude from the list of environment variables populated to the child.
	// If both WhitelistEnv and BlacklistEnv are provided, BlacklistEnv takes
	// precedence over the values in WhitelistEnv.
	Blacklist []string `mapstructure:"blacklist"`

	// CustomEnv specifies custom environment variables to pass to the child
	// process. These are provided programmatically, override any environment
	// variables of the same name, are ignored from whitelist/blacklist, and
	// are still included even if PristineEnv is set to true.
	Custom []string `mapstructure:"custom"`

	// PristineEnv specifies if the child process should inherit the parent's
	// environment.
	Pristine *bool `mapstructure:"pristine"`

	// WhitelistEnv specifies a list of environment variables to exclusively
	// include in the list of environment variables populated to the child.
	Whitelist []string `mapstructure:"whitelist"`
}

EnvConfig is an embeddable struct for things that accept environment variable filtering. You should not use this directly and it is only public for mapstructure's decoding.

func DefaultEnvConfig

func DefaultEnvConfig() *EnvConfig

DefaultEnvConfig returns a configuration that is populated with the default values.

func (*EnvConfig) Copy

func (c *EnvConfig) Copy() *EnvConfig

Copy returns a deep copy of this configuration.

func (*EnvConfig) Env

func (c *EnvConfig) Env() []string

Env calculates and returns the finalized environment for this exec configuration. It takes into account pristine, custom environment, whitelist, and blacklist values.

func (*EnvConfig) Finalize

func (c *EnvConfig) Finalize()

Finalize ensures there no nil pointers.

func (*EnvConfig) GoString

func (c *EnvConfig) GoString() string

GoString defines the printable version of this struct.

func (*EnvConfig) Merge

func (c *EnvConfig) Merge(o *EnvConfig) *EnvConfig

Merge combines all values in this configuration with the values in the other configuration, with values in the other configuration taking precedence. Maps and slices are merged, most other values are overwritten. Complex structs define their own merge functionality.

type RetryConfig

type RetryConfig struct {
	// Attempts is the total number of maximum attempts to retry before letting
	// the error fall through.
	// 0 means unlimited.
	Attempts *int

	// Backoff is the base of the exponentialbackoff. This number will be
	// multiplied by the next power of 2 on each iteration.
	Backoff *time.Duration

	// MaxBackoff is an upper limit to the sleep time between retries
	// A MaxBackoff of zero means there is no limit to the exponential growth of the backoff.
	MaxBackoff *time.Duration `mapstructure:"max_backoff"`

	// Enabled signals if this retry is enabled.
	Enabled *bool
}

RetryConfig is a shared configuration for upstreams that support retires on failure.

func DefaultRetryConfig

func DefaultRetryConfig() *RetryConfig

DefaultRetryConfig returns a configuration that is populated with the default values.

func (*RetryConfig) Copy

func (c *RetryConfig) Copy() *RetryConfig

Copy returns a deep copy of this configuration.

func (*RetryConfig) Finalize

func (c *RetryConfig) Finalize()

Finalize ensures there no nil pointers.

func (*RetryConfig) GoString

func (c *RetryConfig) GoString() string

GoString defines the printable version of this struct.

func (*RetryConfig) Merge

func (c *RetryConfig) Merge(o *RetryConfig) *RetryConfig

Merge combines all values in this configuration with the values in the other configuration, with values in the other configuration taking precedence. Maps and slices are merged, most other values are overwritten. Complex structs define their own merge functionality.

func (*RetryConfig) RetryFunc

func (c *RetryConfig) RetryFunc() RetryFunc

RetryFunc returns the retry function associated with this configuration.

type RetryFunc

type RetryFunc func(int) (bool, time.Duration)

RetryFunc is the signature of a function that supports retries.

type SSLConfig

type SSLConfig struct {
	CaCert     *string `mapstructure:"ca_cert"`
	CaPath     *string `mapstructure:"ca_path"`
	Cert       *string `mapstructure:"cert"`
	Enabled    *bool   `mapstructure:"enabled"`
	Key        *string `mapstructure:"key"`
	ServerName *string `mapstructure:"server_name"`
	Verify     *bool   `mapstructure:"verify"`
}

SSLConfig is the configuration for SSL.

func DefaultSSLConfig

func DefaultSSLConfig() *SSLConfig

DefaultSSLConfig returns a configuration that is populated with the default values.

func (*SSLConfig) Copy

func (c *SSLConfig) Copy() *SSLConfig

Copy returns a deep copy of this configuration.

func (*SSLConfig) Finalize

func (c *SSLConfig) Finalize()

Finalize ensures there no nil pointers.

func (*SSLConfig) GoString

func (c *SSLConfig) GoString() string

GoString defines the printable version of this struct.

func (*SSLConfig) Merge

func (c *SSLConfig) Merge(o *SSLConfig) *SSLConfig

Merge combines all values in this configuration with the values in the other configuration, with values in the other configuration taking precedence. Maps and slices are merged, most other values are overwritten. Complex structs define their own merge functionality.

type SyslogConfig

type SyslogConfig struct {
	Enabled  *bool   `mapstructure:"enabled"`
	Facility *string `mapstructure:"facility"`
}

SyslogConfig is the configuration for syslog.

func DefaultSyslogConfig

func DefaultSyslogConfig() *SyslogConfig

DefaultSyslogConfig returns a configuration that is populated with the default values.

func (*SyslogConfig) Copy

func (c *SyslogConfig) Copy() *SyslogConfig

Copy returns a deep copy of this configuration.

func (*SyslogConfig) Finalize

func (c *SyslogConfig) Finalize()

Finalize ensures there no nil pointers.

func (*SyslogConfig) GoString

func (c *SyslogConfig) GoString() string

GoString defines the printable version of this struct.

func (*SyslogConfig) Merge

func (c *SyslogConfig) Merge(o *SyslogConfig) *SyslogConfig

Merge combines all values in this configuration with the values in the other configuration, with values in the other configuration taking precedence. Maps and slices are merged, most other values are overwritten. Complex structs define their own merge functionality.

type TransportConfig

type TransportConfig struct {
	// DialKeepAlive is the amount of time for keep-alives.
	DialKeepAlive *time.Duration `mapstructure:"dial_keep_alive"`

	// DialTimeout is the amount of time to wait to establish a connection.
	DialTimeout *time.Duration `mapstructure:"dial_timeout"`

	// DisableKeepAlives determines if keep-alives should be used. Disabling this
	// significantly decreases performance.
	DisableKeepAlives *bool `mapstructure:"disable_keep_alives"`

	// IdleConnTimeout is the timeout for idle connections.
	IdleConnTimeout *time.Duration `mapstructure:"idle_conn_timeout"`

	// MaxIdleConns is the maximum number of total idle connections.
	MaxIdleConns *int `mapstructure:"max_idle_conns"`

	// MaxIdleConnsPerHost is the maximum number of idle connections per remote
	// host.
	MaxIdleConnsPerHost *int `mapstructure:"max_idle_conns_per_host"`

	// TLSHandshakeTimeout is the amount of time to wait to complete the TLS
	// handshake.
	TLSHandshakeTimeout *time.Duration `mapstructure:"tls_handshake_timeout"`
}

TransportConfig is the configuration to tune low-level APIs for the interactions on the wire.

func DefaultTransportConfig

func DefaultTransportConfig() *TransportConfig

DefaultTransportConfig returns a configuration that is populated with the default values.

func (*TransportConfig) Copy

func (c *TransportConfig) Copy() *TransportConfig

Copy returns a deep copy of this configuration.

func (*TransportConfig) Finalize

func (c *TransportConfig) Finalize()

Finalize ensures there no nil pointers.

func (*TransportConfig) GoString

func (c *TransportConfig) GoString() string

GoString defines the printable version of this struct.

func (*TransportConfig) Merge

Merge combines all values in this configuration with the values in the other configuration, with values in the other configuration taking precedence. Maps and slices are merged, most other values are overwritten. Complex structs define their own merge functionality.

Jump to

Keyboard shortcuts

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