config

package
v0.0.0-...-beb4b11 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2019 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bool

func Bool(key string) (bool, error)

Bool calls the default Config and returns the bool value of a given key as a bool. It will return an error if the key was not found or the value can't be converted to a bool.

func Duration

func Duration(key string) (time.Duration, error)

Duration calls the default Config and returns the value of the given key as a duration. It will return an error if the key was not found or the value can't be converted to a Duration.

func Init

func Init(p Provider) error

Init populates the package's default Config and should be called only once. A Provider must be supplied which will return a map of key/value pairs to be loaded.

func Int

func Int(key string) (int, error)

Int calls the Default config and returns the value of the given key as an int. It will return an error if the key was not found or the value can't be converted to an int.

func Log

func Log() string

Log returns a string to help with logging the package's default Config. It excludes any values whose key contains the string "PASS".

func MustBool

func MustBool(key string) bool

MustBool calls the default Config and returns the bool value of a given key as a bool. It will panic if the key was not found or the value can't be converted to a bool.

func MustDuration

func MustDuration(key string) time.Duration

MustDuration calls the default Config and returns the value of the given key as a MustDuration. It will panic if the key was not found or the value can't be converted to a MustDuration.

func MustInt

func MustInt(key string) int

MustInt calls the default Config and returns the value of the given key as an int. It will panic if the key was not found or the value can't be converted to an int.

func MustString

func MustString(key string) string

MustString calls the default Config and returns the value of the given key as a string, else it will panic if the key was not found.

func MustTime

func MustTime(key string) time.Time

MustTime calls the default Config ang returns the value of the given key as a Time. It will panic if the key was not found or the value can't be converted to a Time.

func MustURL

func MustURL(key string) *url.URL

MustURL calls the default Config and returns the value of the given key as a URL. It will panic if the key was not found or the value can't be converted to a URL.

func SetBool

func SetBool(key string, value bool)

SetBool adds or modifies the default Config for the specified key and value.

func SetDuration

func SetDuration(key string, value time.Duration)

SetDuration adds or modifies the default Config for the specified key and value.

func SetInt

func SetInt(key string, value int)

SetInt adds or modifies the default Config for the specified key and value.

func SetString

func SetString(key string, value string)

SetString adds or modifies the default Config for the specified key and value.

func SetTime

func SetTime(key string, value time.Time)

SetTime adds or modifies the default Config for the specified key and value.

func SetURL

func SetURL(key string, value *url.URL)

SetURL adds or modifies the default Config for the specified key and value.

func String

func String(key string) (string, error)

String calls the default Config and returns the value of the given key as a string. It will return an error if key was not found.

func Time

func Time(key string) (time.Time, error)

Time calls the default Config and returns the value of the given key as a Time. It will return an error if the key was not found or the value can't be converted to a Time.

func URL

func URL(key string) (*url.URL, error)

URL calls the default Config and returns the value of the given key as a URL. It will return an error if the key was not found or the value can't be converted to a URL.

Types

type Config

type Config struct {
	*sync.RWMutex
	// contains filtered or unexported fields
}

func DefaultConfig

func DefaultConfig() *Config

func New

func New(p Provider) (*Config, error)

func (*Config) Bool

func (c *Config) Bool(key string) (bool, error)

Bool returns the bool value of a given key as a bool. It will return an error if the key was not found or the value can't be converted to a bool.

func (*Config) Duration

func (c *Config) Duration(key string) (time.Duration, error)

Duration returns the value of the given key as a Duration. It will return an error if the key was not found or the value can't be converted to a Duration.

func (*Config) Int

func (c *Config) Int(key string) (int, error)

Int returns the value of the given key as an int. It will return an error if the key was not found or the value can't be converted to an int.

func (*Config) Log

func (c *Config) Log() string

func (*Config) MustBool

func (c *Config) MustBool(key string) bool

MustBool returns the bool value of a given key as a bool. It will panic if the key was not found or the value can't be converted to a bool.

func (*Config) MustDuration

func (c *Config) MustDuration(key string) time.Duration

MustDuration returns the value of the given key as a Duration. It will panic if the key was not found or the value can't be converted into a Duration.

func (*Config) MustInt

func (c *Config) MustInt(key string) int

MustInt returns the value of the given key as an int. It will panic if the key was not found or the value can't be converted to an int.

func (*Config) MustString

func (c *Config) MustString(key string) string

MustString returns the value of the given key as a string. It will panic if the key was not found.

func (*Config) MustTime

func (c *Config) MustTime(key string) time.Time

MustTime returns the value of the given key as a Time. It will panic if the key was not found or the value can't be converted to a Time.

func (*Config) MustURL

func (c *Config) MustURL(key string) *url.URL

MustURL returns the value of the given key as a URL. It will panic if the key was not found or the value can't be converted to a URL.

func (*Config) SetBool

func (c *Config) SetBool(key string, value bool)

SetBool adds or modifies the configuration for the specified key and value.

func (*Config) SetDuration

func (c *Config) SetDuration(key string, value time.Duration)

SetDuration adds or modifies the configuration for a given duration at a specific key.

func (*Config) SetInt

func (c *Config) SetInt(key string, value int)

SetInt adds or modifies the configuration for the specified key and value.

func (*Config) SetString

func (c *Config) SetString(key string, value string)

SetString adds or modifies the configuration for the specified key and value.

func (*Config) SetTime

func (c *Config) SetTime(key string, value time.Time)

SetTime adds or modifies the configuration for the specified key and value.

func (*Config) SetURL

func (c *Config) SetURL(key string, value *url.URL)

SetURL adds or modifies the configuration for the specified key and value.

func (*Config) String

func (c *Config) String(key string) (string, error)

String returns the value of the given key as a string. It will return an error if key was not found.

func (*Config) Time

func (c *Config) Time(key string) (time.Time, error)

Time returns the value of the given key as a Time. It will return an error if the key was not found or the value can't be converted to a Time.

func (*Config) URL

func (c *Config) URL(key string) (*url.URL, error)

URL returns the value of the given key as a URL. It will return an error if the key was not found or the value can't be converted to a URL.

type FileProvider

type FileProvider struct {
	Filename string
}

FileProvider describes a file based loader which loads the configuration from a file listed.

func NewFileProvider

func NewFileProvider(name *string) *FileProvider

func (FileProvider) Provide

func (fp FileProvider) Provide() (map[string]string, error)

Provide implements the Provider interface.

type Provider

type Provider interface {
	Provide() (map[string]string, error)
}

Jump to

Keyboard shortcuts

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