Documentation
      ¶
    
    
  
    
  
    Overview ¶
Package conf provides and implements the interface to manage the Configurations.
Index ¶
- Variables
 - func Get(key string) interface{}
 - func GetBool(key string) bool
 - func GetDuration(key string) time.Duration
 - func GetFloat32(key string) float32
 - func GetFloat64(key string) float64
 - func GetInt(key string) int
 - func GetInt16(key string) int16
 - func GetInt32(key string) int32
 - func GetInt64(key string) int64
 - func GetInt8(key string) int8
 - func GetString(key string) string
 - func GetTime(key string) time.Time
 - func Keys() []string
 - func Load(ctx context.Context) error
 - type Conf
 - type ParseFunc
 - type Parser
 - type Reader
 - type Transform
 
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoParser is an error returned if the parser was not given ErrNoParser = errors.New("no parser") // ErrNoStream is an error returned if the stream was not given ErrNoStream = errors.New("no data stream") )
var BoolValues = map[string]bool{ "yes": true, "Yes": true, "y": true, "Y": true, "On": true, "on": true, }
BoolValues is a global extendable list of the string values that should be converted as true or false
Example:
conf.GetSet("flag", "sí")
conf.GetBool("flag") == false
conf.TrueValues["sí"] = true
conf.GetBool("flag") == true
Functions ¶
func Get ¶
func Get(key string) interface{}
Get returns a value for a given key if it is set or default value Returns `nil` if key not found The alias to work with an instance of the global configuration manager.
func GetBool ¶
GetBool casts a value for a given key to Bool The alias to work with an instance of the global configuration manager.
func GetDuration ¶
GetDuration casts a value for a given key to `time.Duration` The alias to work with an instance of the global configuration manager.
func GetFloat32 ¶
GetFloat32 casts a value for a given key to Float32 The alias to work with an instance of the global configuration manager.
func GetFloat64 ¶
GetFloat64 casts a value for a given key to Float64 The alias to work with an instance of the global configuration manager.
func GetInt ¶
GetInt casts a value for a given key to Int The alias to work with an instance of the global configuration manager.
func GetInt16 ¶
GetInt16 casts a value for a given key to Int16 The alias to work with an instance of the global configuration manager.
func GetInt32 ¶
GetInt32 casts a value for a given key to Int32 The alias to work with an instance of the global configuration manager.
func GetInt64 ¶
GetInt64 casts a value for a given key to Int64 The alias to work with an instance of the global configuration manager.
func GetInt8 ¶
GetInt8 casts a value for a given key to Int8 The alias to work with an instance of the global configuration manager.
func GetString ¶
GetString casts a value for a given key to String The alias to work with an instance of the global configuration manager.
func GetTime ¶
GetTime casts a value for a given key to `time.Time` The alias to work with an instance of the global configuration manager.
Types ¶
type Conf ¶
type Conf interface {
	// WithReaders stores the given readers to load the data in the Load function
	WithReaders(readers ...Reader) Conf
	// WithTransformers stores the given transformers to change the output of the Get function.
	// All trasformers will be applied in the given order.
	WithTransformers(transformers ...Transform) Conf
	// Reset creates an empty storage and clears the old one
	// It does not clear the default values
	// Can be used in the Unit Tests
	Reset() Conf
	// Load calls the `Read` function of all readers  in provided order
	Load(ctx context.Context) error
	// Keys returns the list of the stored keys
	Keys() []string
	// SetDefault sets a default value for a key
	SetDefault(key string, value interface{}) Conf
	// Set overrides the current value of a given key.
	Set(key string, value interface{}) Conf
	Get(key string) interface{}
	// GetString casts a value for a given key to String
	GetString(key string) string
	// GetInt casts a value for a given key to Int
	GetInt(key string) int
	// GetInt8 casts a value for a given key to Int8
	GetInt8(key string) int8
	// GetInt16 casts a value for a given key to Int16
	GetInt16(key string) int16
	// GetInt32 casts a value for a given key to Int32
	GetInt32(key string) int32
	// GetInt64 casts a value for a given key to Int64
	GetInt64(key string) int64
	// GetBool casts a value for a given key to Bool
	GetBool(key string) bool
	// GetFloat32 casts a value for a given key to Float32
	GetFloat32(key string) float32
	// GetFloat64 casts a value for a given key to Float64
	GetFloat64(key string) float64
	// GetTime casts a value for a given key to `time.Time`
	GetTime(key string) time.Time
	// GetDuration casts a value for a given key to `time.Duration`
	GetDuration(key string) time.Duration
}
    Conf is a registry interface
func Reset ¶
func Reset() Conf
Reset creates an empty storage and clears the old one It does not clear the default values Can be used in the Unit Tests The alias to work with an instance of the global configuration manager.
func Set ¶
Set overrides the current value of a given key. The alias to work with an instance of the global configuration manager.
func SetDefault ¶
SetDefault sets a default value for a key The alias to work with an instance of the global configuration manager.
func WithReaders ¶
WithReaders overrides the readers with the given ones The alias to work with an instance of the global configuration manager.
func WithTransformers ¶
WithTransformers stores the given transformers to change the output of the Get function All trasformers will be applied in the given order. The alias to work with an instance of the global configuration manager.
type Parser ¶
type Parser interface {
	Reader
	WithParser(parser ParseFunc) Parser
	WithPrefix(prefix string) Parser
}
    Parser is an extension for the Reader interface.
func NewFileParser ¶
NewFileParser creates an instance of the Parser and opens the given file
func NewStreamParser ¶
NewStreamParser creates an instance of the Parser to read from a given stream