cfg

package
v0.0.0-...-ffea4ed Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidCommaString = errors.New("Invalid comma separated string")
)

Functions

func IsNotFoundErr

func IsNotFoundErr(err error) bool

Types

type Config

type Config struct {
	// contains filtered or unexported fields
}

Config is a go routine safe configuration store structure which can be accessed via providers

func NewConfig

func NewConfig() *Config

NewConfig returns a pointer to an initialised Config

func Parse

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

Parse parses the configuration from a provider and returns a pointer to a configuration store

func (*Config) GetBool

func (c *Config) GetBool(k string) (bool, error)

GetBool gets the requested value from the configuration map and returns it as a boolean. Returns an error if the key can't be found.

func (*Config) GetDuration

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

GetDuration gets the requested value from the configuration map and returns it as a Duration. Returns an error if the key can't be found.

func (*Config) GetFloat

func (c *Config) GetFloat(k string) (float64, error)

GetFloat gets the requested value from the configuration map and returns it as a float64. Returns an error if the key can't be found.

func (*Config) GetInt

func (c *Config) GetInt(k string) (int, error)

GetInt gets the requested value from the configuration map and returns it as an integer. Returns an error if the key can't be found.

func (*Config) GetSlice

func (c *Config) GetSlice(k string) ([]string, error)

GetSlice gets the requested value, which must be a comma separated string, from the configuration map and returns it as a slice. Returns an error if the key can't be found.

func (*Config) GetString

func (c *Config) GetString(k string) (string, error)

GetString gets the requested value from the configuration map and returns it as a string. Returns an error if the key can't be found.

func (*Config) GetTime

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

GetTime gets the requested value from the configuration map and returns it as a Time. Returns an error if the key can't be found.

func (*Config) GetURL

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

GetURL gets the requested value from the configuration map and returns it as a pointer to a URL. Returns an error if the key can't be found.

func (*Config) Len

func (c *Config) Len() int

Len returns the length of the value map

func (*Config) Map

func (c *Config) Map() map[string]string

Map returns the map with configuration values

func (*Config) MustBool

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

MustBool gets the requested value from the configuration map and returns it as a boolean. Panics if the key can't be found.

func (*Config) MustDuration

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

MustDuration gets the requested value from the configuration map and returns it as a Duration. Panics if the key can't be found.

func (*Config) MustFloat

func (c *Config) MustFloat(k string) float64

MustFloat gets the requested value from the configuration map and returns it as a float64. Panics if the key can't be found.

func (*Config) MustInt

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

MustInt gets the requested value from the configuration map and returns it as an integer. Panics if the key can't be found.

func (*Config) MustSlice

func (c *Config) MustSlice(k string) []string

MustSlice gets the requested value, which must be a comma separated string, from the configuration map and returns it as a slice. Panics if the key can't be found.

func (*Config) MustString

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

MustString gets the requested value from the configuration map and returns it as a string. Will panic if the key can't be found.

func (*Config) MustTime

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

MustTime gets the requested value from the configuration map and returns it as a Duration. Panics if the key can't be found.

func (*Config) MustURL

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

MustURL gets the requested value from the configuration map and returns it as a pointer to a URL. Panics if the key can't be found.

func (*Config) SetBool

func (c *Config) SetBool(k string, b bool)

SetBool updates the configuration map with the provided value for the provided key

func (*Config) SetDuration

func (c *Config) SetDuration(k string, d time.Duration)

SetDuration updates the configuration map with the provided value for the provided key

func (*Config) SetFloat

func (c *Config) SetFloat(k string, f float64)

SetFloat updates the configuration map with the provided value for the provided key

func (*Config) SetInt

func (c *Config) SetInt(k string, i int)

SetInt updates the configuration map with the provided value for the provided key

func (*Config) SetSlice

func (c *Config) SetSlice(k string, s []string)

SetSlice updates the configuration map with the provided value for the provided key

func (*Config) SetString

func (c *Config) SetString(k, v string)

SetString updates the configuration map with the provided value for the provided key

func (*Config) SetTime

func (c *Config) SetTime(k string, t time.Time)

SetTime updates the configuration map with the provided value for the provided key

func (*Config) SetURL

func (c *Config) SetURL(k string, u *url.URL)

SetURL updates the configuration map with the provided value for the provided key

func (*Config) String

func (c *Config) String() string

String returns the configuration map as a string

type ErrKeyNotFound

type ErrKeyNotFound struct {
	Key string
}

func (ErrKeyNotFound) Error

func (err ErrKeyNotFound) Error() string

type Provider

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

Provider is an interface to provide the corresponding configuration as a map

Directories

Path Synopsis
providers
env
gob
map
txt

Jump to

Keyboard shortcuts

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