envcfg

package module
v0.0.0-...-5b7141e Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2018 License: MIT Imports: 14 Imported by: 0

README

About envcfg

Documentation

Overview

Package envcfg provides a common way to load configuration variables from the system environment or from based on initial configuration values stored on disk or in a base64 encoded environment variable.

Index

Constants

View Source
const (
	// DefaultVarName is the default environment variable name to load the
	// initial configuration data from.
	DefaultVarName = "APP_CONFIG"

	// DefaultConfigFile is the default file path to load the initial
	// configuration data from.
	DefaultConfigFile = "env/config"

	// DefaultEnvKey is the default runtime environment key.
	DefaultEnvKey = "runtime.environment"

	// DefaultHostKey is the default server hostname key.
	DefaultHostKey = "server.host"

	// DefaultPortKey is the default server port key.
	DefaultPortKey = "server.port"

	// DefaultCertPathKey is the default server certificate path key.
	DefaultCertPathKey = "server.certs"

	// DefaultCertProviderKey is the default server certificate provider key.
	DefaultCertProviderKey = "server.certProvider"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CertificateProvider

type CertificateProvider interface {
	GetCertificate(*tls.ClientHelloInfo) (*tls.Certificate, error)
}

CertificateProvider is the common interface for certificate providers.

type Envcfg

type Envcfg struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Envcfg handles loading configuration variables from system environment variables or from an initial configuration file.

func New

func New(opts ...Option) (*Envcfg, error)

New creates a new environment configuration loader.

func (*Envcfg) AutocertDNSManager

func (ec *Envcfg) AutocertDNSManager(email string, provisioner autocertdns.Provisioner) *autocertdns.Manager

AutocertDNSManager returns an autocertdns.Manager.

func (*Envcfg) AutocertManager

func (ec *Envcfg) AutocertManager() *autocert.Manager

AutocertManager returns an autocert.Manager.

func (*Envcfg) CertPath

func (ec *Envcfg) CertPath() string

CertPath retrieves the value for the server certificate path key.

func (*Envcfg) CertProvider

func (ec *Envcfg) CertProvider() CertificateProvider

CertProvider returns the configured certificate provider.

func (*Envcfg) Env

func (ec *Envcfg) Env() string

Env retrieves the value for the runtime environment key.

func (*Envcfg) GetBool

func (ec *Envcfg) GetBool(key string) bool

GetBool retrieves the value for key from the environment, or the supplied configuration data, returning it as a bool.

func (*Envcfg) GetFloat

func (ec *Envcfg) GetFloat(key string, bitSize int) float64

GetFloat retrieves the value for key from the environment, or the supplied configuration data, returning it as a float64. Uses bitSize as the precision.

func (*Envcfg) GetInt

func (ec *Envcfg) GetInt(key string) int

GetInt retrieves the value for key from the environment, or the supplied configuration data, returning it as a int. Expects numbers to be base 10 and no larger than 32 bits.

func (*Envcfg) GetInt64

func (ec *Envcfg) GetInt64(key string, base, bitSize int) int64

GetInt64 retrieves the value for key from the environment, or the supplied configuration data, returning it as a int64. Uses base and bitSize to parse.

func (*Envcfg) GetKey

func (ec *Envcfg) GetKey(key string) string

GetKey retrieves the value for the key from the environment, or from the initial supplied configuration data.

When the initial value read from the config file or the supplied app environment variable is in the form of "$NAME||<default>" or "$NAME||<default>||<encoding>". Then the value will be read from from the system environment variable $NAME. If that value is empty, then the <default> value will be returned instead. If the third, optional parameter is supplied then the environment variable value (or the default value) will be decoded using the appropriate method.

Current supported <encoding> parameters:

base64 -- value should be base64 decoded
file   -- value should be read from disk

func (*Envcfg) GetString

func (ec *Envcfg) GetString(key string) string

GetString retrieves the value for key from the environment or the supplied configuration data, returning it as a string.

NOTE: alias for GetKey.

func (*Envcfg) GetUint64

func (ec *Envcfg) GetUint64(key string, base, bitSize int) uint64

GetUint64 retrieves the value for key from the environment, or the supplied configuration data, returning it as a uint64. Uses base and bitSize to parse.

func (*Envcfg) Host

func (ec *Envcfg) Host() string

Host retrieves the value for the server host key.

func (*Envcfg) Port

func (ec *Envcfg) Port() int

Port retrieves the value for the server port key.

func (*Envcfg) TLS

func (ec *Envcfg) TLS(certProvider CertificateProvider) *tls.Config

TLS retrieves the TLS configuration, using the provided certificate provider.

type Filter

type Filter func(*Envcfg, string) string

Filter is a func type that modifies a key returned from the envcfg.

type Option

type Option func(*Envcfg)

Option is an Envcfg option.

func CertPathKey

func CertPathKey(key string) Option

CertPathKey is an option that sets the server certificate path key.

func ConfigFile

func ConfigFile(path string) Option

ConfigFile is an option that sets the file path to read data from.

func EnvKey

func EnvKey(key string) Option

EnvKey is an option that sets the runtime environment key.

func HostKey

func HostKey(key string) Option

HostKey is an option that sets the server host key.

func KeyFilter

func KeyFilter(key string, f Filter) Option

KeyFilter is an option that adds a key filter.

func PortKey

func PortKey(key string) Option

PortKey is an option that sets the server port key.

func VarName

func VarName(name string) Option

VarName is an option that sets the name of the environment variable to retrieve the configuration data from.

Jump to

Keyboard shortcuts

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