config

package module
v0.0.0-...-81ae28d Latest Latest
Warning

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

Go to latest
Published: May 29, 2020 License: MIT Imports: 3 Imported by: 11

README

go-config

A super simple config library which uses environment variables or a map as configuration sources.

[Build Status] GitHub go.mod Go version [Go Report Card]

Contributing

Please submit an issue with your proposal.

License

See LICENSE

Documentation

Index

Constants

View Source
const IntDesiredFormat = "int"

IntDesiredFormat is a ErrValueFormat.DesiredFormatDesc variant

Variables

View Source
var ErrEmptyProperty = fmt.Errorf("cannot find a value for an empty property")

ErrEmptyProperty is returned when a config function is given an empty string property

Functions

func LoadProperties

func LoadProperties(typedSource *TypedSource, properties ...property) error

LoadProperties will try load properties from source into variable reference

Types

type EnvSource

type EnvSource struct{}

EnvSource uses os.Env to implement Source

func NewEnvSource

func NewEnvSource() *EnvSource

NewEnvSource is a constructor

func (*EnvSource) GetString

func (es *EnvSource) GetString(property string) (string, error)

GetString implements the Source interface

type ErrPropertyNotSet

type ErrPropertyNotSet struct {
	Property string
}

ErrPropertyNotSet is returned when a property has no corresponding value

func (*ErrPropertyNotSet) Error

func (e *ErrPropertyNotSet) Error() string

Error implements the error interface

type ErrUnknownPropertyType

type ErrUnknownPropertyType struct {
	Type string
}

ErrUnknownPropertyType is returned when a property is not known

func NewErrUnknownPropertyType

func NewErrUnknownPropertyType(typ interface{}) *ErrUnknownPropertyType

NewErrUnknownPropertyType is a constructor

func (*ErrUnknownPropertyType) Error

func (e *ErrUnknownPropertyType) Error() string

Error implements the error interface

type ErrValueFormat

type ErrValueFormat struct {
	Property          string
	ValueString       string
	DesiredFormatDesc string
}

ErrValueFormat is returned when the value found for a property cannot be converted to the desired format

func (*ErrValueFormat) Error

func (e *ErrValueFormat) Error() string

Error implements the error interface

type IntProperty

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

IntProperty holds an int mapping

func IntProp

func IntProp(property string, mapTo *int, required bool) *IntProperty

IntProp constructs IntProperty

type MapSource

type MapSource map[string]string

MapSource resolves config properties to a map

func (MapSource) GetString

func (m MapSource) GetString(property string) (string, error)

GetString implements the Source interface

type Source

type Source interface {
	// Note: property must be in upper case format, like an environment variable.
	GetString(property string) (string, error)
}

Source provides configuration values

type StringProperty

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

StringProperty holds a string mapping

func StrProp

func StrProp(property string, mapTo *string, required bool) *StringProperty

StrProp constructs StringProperty

type TypedSource

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

TypedSource provides typed configuration values from a normal Source

func NewTypedSource

func NewTypedSource(backingSource Source) *TypedSource

NewTypedSource is a constructor

func (*TypedSource) GetInt

func (ts *TypedSource) GetInt(property string) (int, error)

GetInt tries to parse an int from the property, else returns the default.

func (*TypedSource) GetString

func (ts *TypedSource) GetString(property string) (string, error)

GetString implements the Source interface

Jump to

Keyboard shortcuts

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