Documentation ¶
Index ¶
- Constants
- Variables
- func AddHooks(hooks ...Hook)
- func AddParsers(parsers ...Parser)
- func AddProviders(providers ...Provider)
- func Configure(s interface{}) error
- func Initialize(field *Field) error
- type ArgsProvider
- type EnvProvider
- type Field
- type Hook
- type Initializable
- type Parser
- type ParserFunc
- type Processor
- type Provider
- type Repository
- func (r *Repository) AddParsers(parsers ...Parser)
- func (r *Repository) AddProviders(providers ...Provider)
- func (r *Repository) Hook(f *Field) (err error)
- func (r *Repository) Parse(typ reflect.Type, parameter string) (val reflect.Value, err error)
- func (r *Repository) Retrieve(key string) (value, provider string, found bool, err error)
Constants ¶
const ( TagInjectAs = "inject-as" TagInject = "inject" TagKey = "key" TagDefault = "default" TagDescription = "description" )
Variables ¶
var ( Args = NewArgsProvider() Env = NewEnvProvider() )
var DefaultParsers = []Parser{ ParserFunc{reflect.TypeOf((*encoding.TextUnmarshaler)(nil)).Elem(), parseTextUnmarshaler}, ParserFunc{reflect.TypeOf((*encoding.BinaryUnmarshaler)(nil)).Elem(), parseBinaryUnmarshaler}, ParserFunc{reflect.TypeOf([]string(nil)), parseStringSlice}, ParserFunc{reflect.TypeOf(string("")), parseString}, ParserFunc{reflect.TypeOf(bool(false)), parseBool}, ParserFunc{reflect.TypeOf(float32(0)), parseFloat}, ParserFunc{reflect.TypeOf(float64(0)), parseFloat}, ParserFunc{reflect.TypeOf(uint(0)), parseUint}, ParserFunc{reflect.TypeOf(uint8(0)), parseUint}, ParserFunc{reflect.TypeOf(uint16(0)), parseUint}, ParserFunc{reflect.TypeOf(uint32(0)), parseUint}, ParserFunc{reflect.TypeOf(uint64(0)), parseUint}, ParserFunc{reflect.TypeOf(int(0)), parseInt}, ParserFunc{reflect.TypeOf(int8(0)), parseInt}, ParserFunc{reflect.TypeOf(int16(0)), parseInt}, ParserFunc{reflect.TypeOf(int32(0)), parseInt}, ParserFunc{reflect.TypeOf(int64(0)), parseInt}, ParserFunc{reflect.TypeOf(time.Duration(0)), parseDuration}, ParserFunc{reflect.TypeOf(new(regexp.Regexp)), parseRegexp}, }
Functions ¶
func AddProviders ¶
func AddProviders(providers ...Provider)
Add a provider to the default repository.
func Configure ¶
func Configure(s interface{}) error
Configure a service using the default processor.
func Initialize ¶
Types ¶
type ArgsProvider ¶
A Provider that implements the repository.Provider interface.
func NewArgsProvider ¶
func NewArgsProvider() (p *ArgsProvider)
Init fetch all keys available in the command-line and initialize the provider internal storage.
func (*ArgsProvider) Retrieve ¶
func (p *ArgsProvider) Retrieve(key string) (value string, found bool, err error)
Retrieve will return the value from the parsed command-line arguments. Arguments are parsed the first time the method is called. Arguments are expected to be in the form `--key=value` exclusively (for now).
type EnvProvider ¶
A Provider that implements the repository.Provider interface.
func NewEnvProvider ¶
func NewEnvProvider() (p *EnvProvider)
Init fetch all keys available in the command-line and initialize the provider internal storage.
func (EnvProvider) FormatKey ¶
func (EnvProvider) FormatKey(key string) (env string)
type Field ¶
type Field struct { StructField *reflect.StructField Value reflect.Value Path string Parent *Field Children []*Field Tags *structtag.Tags Key string Configurable bool ConfigurationKey string }
func (*Field) IsAnonymous ¶
type Hook ¶
A Hook can be used to act upon every field visited by the repository when configuring a service.
type Initializable ¶
type Initializable interface {
Init() error
}
type Parser ¶
type Parser interface { Parse(reflect.Type, string) (reflect.Value, error) CanParse(reflect.Type) bool }
Parser is the interface implemented by a struct that can convert a raw string representation to a given type.
type ParserFunc ¶
type Processor ¶
type Processor struct {
// contains filtered or unexported fields
}
A Processor handle the service processing and execute hooks on the resulting fields.
func NewProcessor ¶
type Provider ¶
type Provider interface { Retrieve(key string) (value string, found bool, err error) Name() string Priority() int }
Provider is the interface implemented by all entity a configuration key can be retrieved from.
type Repository ¶
type Repository struct {
// contains filtered or unexported fields
}
A Repository is list of configuration providers and hooks.
func (*Repository) AddParsers ¶
func (r *Repository) AddParsers(parsers ...Parser)
Register allow anyone to add a custom parser to the list.
func (*Repository) AddProviders ¶
func (r *Repository) AddProviders(providers ...Provider)
Register a new Provider in this repository.
func (*Repository) Hook ¶
func (r *Repository) Hook(f *Field) (err error)