Documentation ¶
Overview ¶
Package gconf is an extensible and powerful go configuration manager.
Features
- A atomic key-value configuration center.
- Support kinds of decoders to decode the data from the source.
- Support to get the configuration data from many data sources.
- Support to change of the configuration option thread-safely during running.
- Support to observe the change of the configration options.
Index ¶
- Variables
- func AddAndParseOptFlag(c *Config, flagSet ...*flag.FlagSet) error
- func AddDecoder(_type string, decoder Decoder)
- func AddOptFlag(c *Config, flagSet ...*flag.FlagSet)
- func Get(name string) interface{}
- func GetBool(name string) bool
- func GetDuration(name string) time.Duration
- func GetDurationSlice(name string) []time.Duration
- func GetFloat64(name string) float64
- func GetFloat64Slice(name string) []float64
- func GetGroupSep() (sep string)
- func GetInt(name string) int
- func GetInt16(name string) int16
- func GetInt32(name string) int32
- func GetInt64(name string) int64
- func GetIntSlice(name string) []int
- func GetString(name string) string
- func GetStringSlice(name string) []string
- func GetTime(name string) time.Time
- func GetUint(name string) uint
- func GetUint16(name string) uint16
- func GetUint32(name string) uint32
- func GetUint64(name string) uint64
- func GetUintSlice(name string) []uint
- func LoadAndWatchSource(source Source, force ...bool) error
- func LoadBackupFile(filename string) error
- func LoadDataSet(ds DataSet, force ...bool) error
- func LoadMap(options map[string]interface{}, force ...bool) error
- func LoadSource(source Source, force ...bool) error
- func Must(name string) interface{}
- func Observe(observers ...Observer)
- func PrintFlagUsage(flagSet *flag.FlagSet)
- func RegisterOpts(opts ...Opt)
- func Set(name string, value interface{}) error
- func SetVersion(version string)
- func Snapshot() (generation uint64, snap map[string]interface{})
- func UnregisterOpts(optNames ...string)
- type Config
- func (c *Config) AddDecoder(_type string, decoder Decoder)
- func (c *Config) AddDecoderTypeAliases(_type string, aliases ...string)
- func (c *Config) Get(name string) (value interface{})
- func (c *Config) GetAllOpts() []Opt
- func (c *Config) GetBool(name string) bool
- func (c *Config) GetDecoder(_type string) (decoder Decoder)
- func (c *Config) GetDuration(name string) time.Duration
- func (c *Config) GetDurationSlice(name string) []time.Duration
- func (c *Config) GetFloat64(name string) float64
- func (c *Config) GetFloat64Slice(name string) []float64
- func (c *Config) GetGroupSep() (sep string)
- func (c *Config) GetInt(name string) int
- func (c *Config) GetInt16(name string) int16
- func (c *Config) GetInt32(name string) int32
- func (c *Config) GetInt64(name string) int64
- func (c *Config) GetIntSlice(name string) []int
- func (c *Config) GetOpt(name string) (opt Opt, ok bool)
- func (c *Config) GetString(name string) string
- func (c *Config) GetStringSlice(name string) []string
- func (c *Config) GetTime(name string) time.Time
- func (c *Config) GetUint(name string) uint
- func (c *Config) GetUint16(name string) uint16
- func (c *Config) GetUint32(name string) uint32
- func (c *Config) GetUint64(name string) uint64
- func (c *Config) GetUintSlice(name string) []uint
- func (c *Config) Group(name string) *OptGroup
- func (c *Config) HasOpt(name string) (yes bool)
- func (c *Config) IgnoreNoOptError(ignore bool)
- func (c *Config) LoadAndWatchSource(source Source, force ...bool) (err error)
- func (c *Config) LoadBackupFile(filename string) (err error)
- func (c *Config) LoadDataSet(ds DataSet, force ...bool) (err error)
- func (c *Config) LoadMap(options map[string]interface{}, force ...bool) error
- func (c *Config) LoadSource(source Source, force ...bool) (err error)
- func (c *Config) Must(name string) (value interface{})
- func (c *Config) NewBool(name string, _default bool, help string) *OptProxyBool
- func (c *Config) NewDuration(name string, _default time.Duration, help string) *OptProxyDuration
- func (c *Config) NewDurationSlice(name string, _default []time.Duration, help string) *OptProxyDurationSlice
- func (c *Config) NewFloat64(name string, _default float64, help string) *OptProxyFloat64
- func (c *Config) NewFloat64Slice(name string, _default []float64, help string) *OptProxyFloat64Slice
- func (c *Config) NewInt(name string, _default int, help string) *OptProxyInt
- func (c *Config) NewInt16(name string, _default int16, help string) *OptProxyInt16
- func (c *Config) NewInt32(name string, _default int32, help string) *OptProxyInt32
- func (c *Config) NewInt64(name string, _default int64, help string) *OptProxyInt64
- func (c *Config) NewIntSlice(name string, _default []int, help string) *OptProxyIntSlice
- func (c *Config) NewOptProxy(opt Opt) OptProxy
- func (c *Config) NewString(name, _default, help string) *OptProxyString
- func (c *Config) NewStringSlice(name string, _default []string, help string) *OptProxyStringSlice
- func (c *Config) NewTime(name string, _default time.Time, help string) *OptProxyTime
- func (c *Config) NewUint(name string, _default uint, help string) *OptProxyUint
- func (c *Config) NewUint16(name string, _default uint16, help string) *OptProxyUint16
- func (c *Config) NewUint32(name string, _default uint32, help string) *OptProxyUint32
- func (c *Config) NewUint64(name string, _default uint64, help string) *OptProxyUint64
- func (c *Config) NewUintSlice(name string, _default []uint, help string) *OptProxyUintSlice
- func (c *Config) Observe(observers ...Observer)
- func (c *Config) OptIsSet(name string) (yes bool)
- func (c *Config) Parse(name string, value interface{}) (interface{}, error)
- func (c *Config) RegisterOpts(opts ...Opt)
- func (c *Config) Set(name string, value interface{}) (err error)
- func (c *Config) SetVersion(version string)
- func (c *Config) Snapshot() (generation uint64, snap map[string]interface{})
- func (c *Config) Stop()
- func (c *Config) UnregisterOpts(optNames ...string)
- type DataSet
- type Decoder
- type Observer
- type Opt
- func BoolOpt(name string, help string) Opt
- func DurationOpt(name string, help string) Opt
- func DurationSliceOpt(name string, help string) Opt
- func Float64Opt(name string, help string) Opt
- func Float64SliceOpt(name string, help string) Opt
- func GetAllOpts() []Opt
- func Int16Opt(name string, help string) Opt
- func Int32Opt(name string, help string) Opt
- func Int64Opt(name string, help string) Opt
- func IntOpt(name string, help string) Opt
- func IntSliceOpt(name string, help string) Opt
- func NewOpt(name, help string, _default interface{}, parser Parser) Opt
- func StrOpt(name string, help string) Opt
- func StrSliceOpt(name string, help string) Opt
- func TimeOpt(name string, help string) Opt
- func Uint16Opt(name string, help string) Opt
- func Uint32Opt(name string, help string) Opt
- func Uint64Opt(name string, help string) Opt
- func UintOpt(name string, help string) Opt
- func UintSliceOpt(name string, help string) Opt
- func (o Opt) As(aliases ...string) Opt
- func (o Opt) Cli(cli bool) Opt
- func (o Opt) D(_default interface{}) Opt
- func (o Opt) H(help string) Opt
- func (o Opt) N(name string) Opt
- func (o Opt) P(parser Parser) Opt
- func (o Opt) S(shortName string) Opt
- func (o Opt) U(callback func(oldValue, newValue interface{})) Opt
- func (o Opt) V(validators ...Validator) Opt
- type OptGroup
- func (g *OptGroup) Get(name string) interface{}
- func (g *OptGroup) GetAllOpts() []Opt
- func (g *OptGroup) GetBool(name string) bool
- func (g *OptGroup) GetDuration(name string) time.Duration
- func (g *OptGroup) GetDurationSlice(name string) []time.Duration
- func (g *OptGroup) GetFloat64(name string) float64
- func (g *OptGroup) GetFloat64Slice(name string) []float64
- func (g *OptGroup) GetInt(name string) int
- func (g *OptGroup) GetInt16(name string) int16
- func (g *OptGroup) GetInt32(name string) int32
- func (g *OptGroup) GetInt64(name string) int64
- func (g *OptGroup) GetIntSlice(name string) []int
- func (g *OptGroup) GetOpt(name string) (opt Opt, ok bool)
- func (g *OptGroup) GetString(name string) string
- func (g *OptGroup) GetStringSlice(name string) []string
- func (g *OptGroup) GetTime(name string) time.Time
- func (g *OptGroup) GetUint(name string) uint
- func (g *OptGroup) GetUint16(name string) uint16
- func (g *OptGroup) GetUint32(name string) uint32
- func (g *OptGroup) GetUint64(name string) uint64
- func (g *OptGroup) GetUintSlice(name string) []uint
- func (g *OptGroup) Group(name string) *OptGroup
- func (g *OptGroup) HasOpt(name string) (yes bool)
- func (g *OptGroup) Must(name string) interface{}
- func (g *OptGroup) NewBool(name string, _default bool, help string) *OptProxyBool
- func (g *OptGroup) NewDuration(name string, _default time.Duration, help string) *OptProxyDuration
- func (g *OptGroup) NewDurationSlice(name string, _default []time.Duration, help string) *OptProxyDurationSlice
- func (g *OptGroup) NewFloat64(name string, _default float64, help string) *OptProxyFloat64
- func (g *OptGroup) NewFloat64Slice(name string, _default []float64, help string) *OptProxyFloat64Slice
- func (g *OptGroup) NewInt(name string, _default int, help string) *OptProxyInt
- func (g *OptGroup) NewInt16(name string, _default int16, help string) *OptProxyInt16
- func (g *OptGroup) NewInt32(name string, _default int32, help string) *OptProxyInt32
- func (g *OptGroup) NewInt64(name string, _default int64, help string) *OptProxyInt64
- func (g *OptGroup) NewIntSlice(name string, _default []int, help string) *OptProxyIntSlice
- func (g *OptGroup) NewOptProxy(opt Opt) OptProxy
- func (g *OptGroup) NewString(name, _default, help string) *OptProxyString
- func (g *OptGroup) NewStringSlice(name string, _default []string, help string) *OptProxyStringSlice
- func (g *OptGroup) NewTime(name string, _default time.Time, help string) *OptProxyTime
- func (g *OptGroup) NewUint(name string, _default uint, help string) *OptProxyUint
- func (g *OptGroup) NewUint16(name string, _default uint16, help string) *OptProxyUint16
- func (g *OptGroup) NewUint32(name string, _default uint32, help string) *OptProxyUint32
- func (g *OptGroup) NewUint64(name string, _default uint64, help string) *OptProxyUint64
- func (g *OptGroup) NewUintSlice(name string, _default []uint, help string) *OptProxyUintSlice
- func (g *OptGroup) OptIsSet(name string) (yes bool)
- func (g *OptGroup) Prefix() string
- func (g *OptGroup) RegisterOpts(opts ...Opt)
- func (g *OptGroup) SelfBool(help string) *OptProxyBool
- func (g *OptGroup) Set(name string, value interface{}) error
- func (g *OptGroup) UnregisterOpts(optNames ...string)
- type OptProxy
- func (o *OptProxy) Aliases(aliases ...string) *OptProxy
- func (o *OptProxy) Default(_default interface{}) *OptProxy
- func (o *OptProxy) Get() interface{}
- func (o *OptProxy) IsCli(cli bool) *OptProxy
- func (o *OptProxy) Name() string
- func (o *OptProxy) OnUpdate(callback func(old, new interface{})) *OptProxy
- func (o *OptProxy) Opt() Opt
- func (o *OptProxy) Parser(parser Parser) *OptProxy
- func (o *OptProxy) Set(value interface{}) (err error)
- func (o *OptProxy) Short(short string) *OptProxy
- func (o OptProxy) ToBool() *OptProxyBool
- func (o OptProxy) ToDuration() *OptProxyDuration
- func (o OptProxy) ToDurationSlice() *OptProxyDurationSlice
- func (o OptProxy) ToFloat64() *OptProxyFloat64
- func (o OptProxy) ToFloat64Slice() *OptProxyFloat64Slice
- func (o OptProxy) ToInt() *OptProxyInt
- func (o OptProxy) ToInt16() *OptProxyInt16
- func (o OptProxy) ToInt32() *OptProxyInt32
- func (o OptProxy) ToInt64() *OptProxyInt64
- func (o OptProxy) ToIntSlice() *OptProxyIntSlice
- func (o OptProxy) ToString() *OptProxyString
- func (o OptProxy) ToStringSlice() *OptProxyStringSlice
- func (o OptProxy) ToTime() *OptProxyTime
- func (o OptProxy) ToUint() *OptProxyUint
- func (o OptProxy) ToUint16() *OptProxyUint16
- func (o OptProxy) ToUint32() *OptProxyUint32
- func (o OptProxy) ToUint64() *OptProxyUint64
- func (o OptProxy) ToUintSlice() *OptProxyUintSlice
- func (o *OptProxy) Validators(validators ...Validator) *OptProxy
- type OptProxyBool
- func (o *OptProxyBool) Aliases(aliases ...string) *OptProxyBool
- func (o *OptProxyBool) Default(_default interface{}) *OptProxyBool
- func (o *OptProxyBool) Get() bool
- func (o *OptProxyBool) IsCli(cli bool) *OptProxyBool
- func (o *OptProxyBool) Name() string
- func (o *OptProxyBool) OnUpdate(f func(old, new interface{})) *OptProxyBool
- func (o *OptProxyBool) Opt() Opt
- func (o *OptProxyBool) Parser(parser Parser) *OptProxyBool
- func (o *OptProxyBool) Set(value interface{}) (err error)
- func (o *OptProxyBool) Short(short string) *OptProxyBool
- func (o *OptProxyBool) Validators(validators ...Validator) *OptProxyBool
- type OptProxyDuration
- func (o *OptProxyDuration) Aliases(aliases ...string) *OptProxyDuration
- func (o *OptProxyDuration) Default(_default interface{}) *OptProxyDuration
- func (o *OptProxyDuration) Get() time.Duration
- func (o *OptProxyDuration) IsCli(cli bool) *OptProxyDuration
- func (o *OptProxyDuration) Name() string
- func (o *OptProxyDuration) OnUpdate(f func(old, new interface{})) *OptProxyDuration
- func (o *OptProxyDuration) Opt() Opt
- func (o *OptProxyDuration) Parser(parser Parser) *OptProxyDuration
- func (o *OptProxyDuration) Set(value interface{}) (err error)
- func (o *OptProxyDuration) Short(short string) *OptProxyDuration
- func (o *OptProxyDuration) Validators(validators ...Validator) *OptProxyDuration
- type OptProxyDurationSlice
- func (o *OptProxyDurationSlice) Aliases(aliases ...string) *OptProxyDurationSlice
- func (o *OptProxyDurationSlice) Default(_default interface{}) *OptProxyDurationSlice
- func (o *OptProxyDurationSlice) Get() []time.Duration
- func (o *OptProxyDurationSlice) IsCli(cli bool) *OptProxyDurationSlice
- func (o *OptProxyDurationSlice) Name() string
- func (o *OptProxyDurationSlice) OnUpdate(f func(old, new interface{})) *OptProxyDurationSlice
- func (o *OptProxyDurationSlice) Opt() Opt
- func (o *OptProxyDurationSlice) Parser(parser Parser) *OptProxyDurationSlice
- func (o *OptProxyDurationSlice) Set(value interface{}) (err error)
- func (o *OptProxyDurationSlice) Short(short string) *OptProxyDurationSlice
- func (o *OptProxyDurationSlice) Validators(validators ...Validator) *OptProxyDurationSlice
- type OptProxyFloat64
- func (o *OptProxyFloat64) Aliases(aliases ...string) *OptProxyFloat64
- func (o *OptProxyFloat64) Default(_default interface{}) *OptProxyFloat64
- func (o *OptProxyFloat64) Get() float64
- func (o *OptProxyFloat64) IsCli(cli bool) *OptProxyFloat64
- func (o *OptProxyFloat64) Name() string
- func (o *OptProxyFloat64) OnUpdate(f func(old, new interface{})) *OptProxyFloat64
- func (o *OptProxyFloat64) Opt() Opt
- func (o *OptProxyFloat64) Parser(parser Parser) *OptProxyFloat64
- func (o *OptProxyFloat64) Set(value interface{}) (err error)
- func (o *OptProxyFloat64) Short(short string) *OptProxyFloat64
- func (o *OptProxyFloat64) Validators(validators ...Validator) *OptProxyFloat64
- type OptProxyFloat64Slice
- func (o *OptProxyFloat64Slice) Aliases(aliases ...string) *OptProxyFloat64Slice
- func (o *OptProxyFloat64Slice) Default(_default interface{}) *OptProxyFloat64Slice
- func (o *OptProxyFloat64Slice) Get() []float64
- func (o *OptProxyFloat64Slice) IsCli(cli bool) *OptProxyFloat64Slice
- func (o *OptProxyFloat64Slice) Name() string
- func (o *OptProxyFloat64Slice) OnUpdate(f func(old, new interface{})) *OptProxyFloat64Slice
- func (o *OptProxyFloat64Slice) Opt() Opt
- func (o *OptProxyFloat64Slice) Parser(parser Parser) *OptProxyFloat64Slice
- func (o *OptProxyFloat64Slice) Set(value interface{}) (err error)
- func (o *OptProxyFloat64Slice) Short(short string) *OptProxyFloat64Slice
- func (o *OptProxyFloat64Slice) Validators(validators ...Validator) *OptProxyFloat64Slice
- type OptProxyInt
- func (o *OptProxyInt) Aliases(aliases ...string) *OptProxyInt
- func (o *OptProxyInt) Default(_default interface{}) *OptProxyInt
- func (o *OptProxyInt) Get() int
- func (o *OptProxyInt) IsCli(cli bool) *OptProxyInt
- func (o *OptProxyInt) Name() string
- func (o *OptProxyInt) OnUpdate(f func(old, new interface{})) *OptProxyInt
- func (o *OptProxyInt) Opt() Opt
- func (o *OptProxyInt) Parser(parser Parser) *OptProxyInt
- func (o *OptProxyInt) Set(value interface{}) (err error)
- func (o *OptProxyInt) Short(short string) *OptProxyInt
- func (o *OptProxyInt) Validators(validators ...Validator) *OptProxyInt
- type OptProxyInt16
- func (o *OptProxyInt16) Aliases(aliases ...string) *OptProxyInt16
- func (o *OptProxyInt16) Default(_default interface{}) *OptProxyInt16
- func (o *OptProxyInt16) Get() int16
- func (o *OptProxyInt16) IsCli(cli bool) *OptProxyInt16
- func (o *OptProxyInt16) Name() string
- func (o *OptProxyInt16) OnUpdate(f func(old, new interface{})) *OptProxyInt16
- func (o *OptProxyInt16) Opt() Opt
- func (o *OptProxyInt16) Parser(parser Parser) *OptProxyInt16
- func (o *OptProxyInt16) Set(value interface{}) (err error)
- func (o *OptProxyInt16) Short(short string) *OptProxyInt16
- func (o *OptProxyInt16) Validators(validators ...Validator) *OptProxyInt16
- type OptProxyInt32
- func (o *OptProxyInt32) Aliases(aliases ...string) *OptProxyInt32
- func (o *OptProxyInt32) Default(_default interface{}) *OptProxyInt32
- func (o *OptProxyInt32) Get() int32
- func (o *OptProxyInt32) IsCli(cli bool) *OptProxyInt32
- func (o *OptProxyInt32) Name() string
- func (o *OptProxyInt32) OnUpdate(f func(old, new interface{})) *OptProxyInt32
- func (o *OptProxyInt32) Opt() Opt
- func (o *OptProxyInt32) Parser(parser Parser) *OptProxyInt32
- func (o *OptProxyInt32) Set(value interface{}) (err error)
- func (o *OptProxyInt32) Short(short string) *OptProxyInt32
- func (o *OptProxyInt32) Validators(validators ...Validator) *OptProxyInt32
- type OptProxyInt64
- func (o *OptProxyInt64) Aliases(aliases ...string) *OptProxyInt64
- func (o *OptProxyInt64) Default(_default interface{}) *OptProxyInt64
- func (o *OptProxyInt64) Get() int64
- func (o *OptProxyInt64) IsCli(cli bool) *OptProxyInt64
- func (o *OptProxyInt64) Name() string
- func (o *OptProxyInt64) OnUpdate(f func(old, new interface{})) *OptProxyInt64
- func (o *OptProxyInt64) Opt() Opt
- func (o *OptProxyInt64) Parser(parser Parser) *OptProxyInt64
- func (o *OptProxyInt64) Set(value interface{}) (err error)
- func (o *OptProxyInt64) Short(short string) *OptProxyInt64
- func (o *OptProxyInt64) Validators(validators ...Validator) *OptProxyInt64
- type OptProxyIntSlice
- func (o *OptProxyIntSlice) Aliases(aliases ...string) *OptProxyIntSlice
- func (o *OptProxyIntSlice) Default(_default interface{}) *OptProxyIntSlice
- func (o *OptProxyIntSlice) Get() []int
- func (o *OptProxyIntSlice) IsCli(cli bool) *OptProxyIntSlice
- func (o *OptProxyIntSlice) Name() string
- func (o *OptProxyIntSlice) OnUpdate(f func(old, new interface{})) *OptProxyIntSlice
- func (o *OptProxyIntSlice) Opt() Opt
- func (o *OptProxyIntSlice) Parser(parser Parser) *OptProxyIntSlice
- func (o *OptProxyIntSlice) Set(value interface{}) (err error)
- func (o *OptProxyIntSlice) Short(short string) *OptProxyIntSlice
- func (o *OptProxyIntSlice) Validators(validators ...Validator) *OptProxyIntSlice
- type OptProxyString
- func (o *OptProxyString) Aliases(aliases ...string) *OptProxyString
- func (o *OptProxyString) Default(_default interface{}) *OptProxyString
- func (o *OptProxyString) Get() string
- func (o *OptProxyString) IsCli(cli bool) *OptProxyString
- func (o *OptProxyString) Name() string
- func (o *OptProxyString) OnUpdate(f func(old, new interface{})) *OptProxyString
- func (o *OptProxyString) Opt() Opt
- func (o *OptProxyString) Parser(parser Parser) *OptProxyString
- func (o *OptProxyString) Set(value interface{}) (err error)
- func (o *OptProxyString) Short(short string) *OptProxyString
- func (o *OptProxyString) Validators(validators ...Validator) *OptProxyString
- type OptProxyStringSlice
- func (o *OptProxyStringSlice) Aliases(aliases ...string) *OptProxyStringSlice
- func (o *OptProxyStringSlice) Default(_default interface{}) *OptProxyStringSlice
- func (o *OptProxyStringSlice) Get() []string
- func (o *OptProxyStringSlice) IsCli(cli bool) *OptProxyStringSlice
- func (o *OptProxyStringSlice) Name() string
- func (o *OptProxyStringSlice) OnUpdate(f func(old, new interface{})) *OptProxyStringSlice
- func (o *OptProxyStringSlice) Opt() Opt
- func (o *OptProxyStringSlice) Parser(parser Parser) *OptProxyStringSlice
- func (o *OptProxyStringSlice) Set(value interface{}) (err error)
- func (o *OptProxyStringSlice) Short(short string) *OptProxyStringSlice
- func (o *OptProxyStringSlice) Validators(validators ...Validator) *OptProxyStringSlice
- type OptProxyTime
- func (o *OptProxyTime) Aliases(aliases ...string) *OptProxyTime
- func (o *OptProxyTime) Default(_default interface{}) *OptProxyTime
- func (o *OptProxyTime) Get() time.Time
- func (o *OptProxyTime) IsCli(cli bool) *OptProxyTime
- func (o *OptProxyTime) Name() string
- func (o *OptProxyTime) OnUpdate(f func(old, new interface{})) *OptProxyTime
- func (o *OptProxyTime) Opt() Opt
- func (o *OptProxyTime) Parser(parser Parser) *OptProxyTime
- func (o *OptProxyTime) Set(value interface{}) (err error)
- func (o *OptProxyTime) Short(short string) *OptProxyTime
- func (o *OptProxyTime) Validators(validators ...Validator) *OptProxyTime
- type OptProxyUint
- func (o *OptProxyUint) Aliases(aliases ...string) *OptProxyUint
- func (o *OptProxyUint) Default(_default interface{}) *OptProxyUint
- func (o *OptProxyUint) Get() uint
- func (o *OptProxyUint) IsCli(cli bool) *OptProxyUint
- func (o *OptProxyUint) Name() string
- func (o *OptProxyUint) OnUpdate(f func(old, new interface{})) *OptProxyUint
- func (o *OptProxyUint) Opt() Opt
- func (o *OptProxyUint) Parser(parser Parser) *OptProxyUint
- func (o *OptProxyUint) Set(value interface{}) (err error)
- func (o *OptProxyUint) Short(short string) *OptProxyUint
- func (o *OptProxyUint) Validators(validators ...Validator) *OptProxyUint
- type OptProxyUint16
- func (o *OptProxyUint16) Aliases(aliases ...string) *OptProxyUint16
- func (o *OptProxyUint16) Default(_default interface{}) *OptProxyUint16
- func (o *OptProxyUint16) Get() uint16
- func (o *OptProxyUint16) IsCli(cli bool) *OptProxyUint16
- func (o *OptProxyUint16) Name() string
- func (o *OptProxyUint16) OnUpdate(f func(old, new interface{})) *OptProxyUint16
- func (o *OptProxyUint16) Opt() Opt
- func (o *OptProxyUint16) Parser(parser Parser) *OptProxyUint16
- func (o *OptProxyUint16) Set(value interface{}) (err error)
- func (o *OptProxyUint16) Short(short string) *OptProxyUint16
- func (o *OptProxyUint16) Validators(validators ...Validator) *OptProxyUint16
- type OptProxyUint32
- func (o *OptProxyUint32) Aliases(aliases ...string) *OptProxyUint32
- func (o *OptProxyUint32) Default(_default interface{}) *OptProxyUint32
- func (o *OptProxyUint32) Get() uint32
- func (o *OptProxyUint32) IsCli(cli bool) *OptProxyUint32
- func (o *OptProxyUint32) Name() string
- func (o *OptProxyUint32) OnUpdate(f func(old, new interface{})) *OptProxyUint32
- func (o *OptProxyUint32) Opt() Opt
- func (o *OptProxyUint32) Parser(parser Parser) *OptProxyUint32
- func (o *OptProxyUint32) Set(value interface{}) (err error)
- func (o *OptProxyUint32) Short(short string) *OptProxyUint32
- func (o *OptProxyUint32) Validators(validators ...Validator) *OptProxyUint32
- type OptProxyUint64
- func (o *OptProxyUint64) Aliases(aliases ...string) *OptProxyUint64
- func (o *OptProxyUint64) Default(_default interface{}) *OptProxyUint64
- func (o *OptProxyUint64) Get() uint64
- func (o *OptProxyUint64) IsCli(cli bool) *OptProxyUint64
- func (o *OptProxyUint64) Name() string
- func (o *OptProxyUint64) OnUpdate(f func(old, new interface{})) *OptProxyUint64
- func (o *OptProxyUint64) Opt() Opt
- func (o *OptProxyUint64) Parser(parser Parser) *OptProxyUint64
- func (o *OptProxyUint64) Set(value interface{}) (err error)
- func (o *OptProxyUint64) Short(short string) *OptProxyUint64
- func (o *OptProxyUint64) Validators(validators ...Validator) *OptProxyUint64
- type OptProxyUintSlice
- func (o *OptProxyUintSlice) Aliases(aliases ...string) *OptProxyUintSlice
- func (o *OptProxyUintSlice) Default(_default interface{}) *OptProxyUintSlice
- func (o *OptProxyUintSlice) Get() []uint
- func (o *OptProxyUintSlice) IsCli(cli bool) *OptProxyUintSlice
- func (o *OptProxyUintSlice) Name() string
- func (o *OptProxyUintSlice) OnUpdate(f func(old, new interface{})) *OptProxyUintSlice
- func (o *OptProxyUintSlice) Opt() Opt
- func (o *OptProxyUintSlice) Parser(parser Parser) *OptProxyUintSlice
- func (o *OptProxyUintSlice) Set(value interface{}) (err error)
- func (o *OptProxyUintSlice) Short(short string) *OptProxyUintSlice
- func (o *OptProxyUintSlice) Validators(validators ...Validator) *OptProxyUintSlice
- type Parser
- type Source
- type Validator
- func NewAddressOrIPSliceValidator() Validator
- func NewAddressOrIPValidator() Validator
- func NewAddressSliceValidator() Validator
- func NewAddressValidator() Validator
- func NewEmailSliceValidator() Validator
- func NewEmailValidator() Validator
- func NewEmptyStrValidator() Validator
- func NewFloatRangeValidator(min, max float64) Validator
- func NewIPSliceValidator() Validator
- func NewIPValidator() Validator
- func NewIntegerRangeValidator(min, max int64) Validator
- func NewMaybeAddressOrIPValidator() Validator
- func NewMaybeAddressValidator() Validator
- func NewMaybeEmailValidator() Validator
- func NewMaybeIPValidator() Validator
- func NewMaybeURLValidator() Validator
- func NewPortValidator() Validator
- func NewRegexpValidator(pattern string) Validator
- func NewStrArrayValidator(array []string) Validator
- func NewStrLenValidator(min, max int) Validator
- func NewStrNotEmptyValidator() Validator
- func NewStrSliceValidator(strValidators ...Validator) Validator
- func NewURLSliceValidator() Validator
- func NewURLValidator() Validator
- func Or(validators ...Validator) Validator
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( ToBool = defaults.ToBool // func(interface{}) (bool, error) ToInt64 = defaults.ToInt64 // func(interface{}) (int64, error) ToUint64 = defaults.ToUint64 // func(interface{}) (uint64, error) ToFloat64 = defaults.ToFloat64 // func(interface{}) (float64, error) ToString = defaults.ToString // func(interface{}) (string, error) ToDuration = defaults.ToDuration // func(interface{}) (time.Duration, error) ToTime = defaults.ToTime // func(interface{}) (time.Time, error) ToInt = toInt // func(interface{}) (int, error) ToInt16 = toInt16 // func(interface{}) (int16, error) ToInt32 = toInt32 // func(interface{}) (int32, error) ToUint = toUint // func(interface{}) (uint, error) ToUint16 = toUint16 // func(interface{}) (uint16, error) ToUint32 = toUint32 // func(interface{}) (uint32, error) // For string type, it will be split by the separator " " or ",". ToIntSlice = toIntSlice // func(interface{}) ([]int, error) ToUintSlice = toUintSlice // func(interface{}) ([]uint, error) ToFloat64Slice = toFloat64Slice // func(interface{}) ([]float64, error) ToStringSlice = toStringSlice // func(interface{}) ([]string, error) ToDurationSlice = toDurationSlice // func(interface{}) ([]time.Duration, error) )
Some type converters, all of which have a default implementation, but you can reset them to yourself implementations.
var ( AddressOrIPSliceValidator = NewAddressOrIPSliceValidator() AddressOrIPValidator = NewAddressOrIPValidator() AddressSliceValidator = NewAddressSliceValidator() AddressValidator = NewAddressValidator() EmailSliceValidator = NewEmailSliceValidator() EmailValidator = NewEmailValidator() EmptyStrValidator = NewEmptyStrValidator() IPSliceValidator = NewIPSliceValidator() IPValidator = NewIPValidator() MaybeAddressOrIPValidator = NewMaybeAddressOrIPValidator() MaybeAddressValidator = NewMaybeAddressValidator() MaybeEmailValidator = NewMaybeEmailValidator() MaybeIPValidator = NewMaybeIPValidator() MaybeURLValidator = NewMaybeURLValidator() PortValidator = NewPortValidator() StrNotEmptyValidator = NewStrNotEmptyValidator() URLSliceValidator = NewURLSliceValidator() URLValidator = NewURLValidator() )
Predefine some constant validators.
var Conf = New()
Conf is the default global Config.
var ConfigFileOpt = StrOpt("config-file", "the config file path.")
ConfigFileOpt is the default option for the configuration file.
var ErrNoDecoder = errors.New("no decoder")
ErrNoDecoder represents the error that there is no decoder.
var ErrNoOpt = errors.New("no option")
ErrNoOpt represents an error that the option does not exist.
var VersionOpt = StrOpt("version", "Print the version and exit.").S("v").D("1.0.0")
VersionOpt reprensents a version option.
Functions ¶
func AddAndParseOptFlag ¶
AddAndParseOptFlag is the same as AddOptFlag, but parses the CLI arguments.
Notice: if there is the version flag and it is true, it will print the version and exit.
func AddDecoder ¶
AddDecoder is equal to Conf.AddDecoder(_type, decoder).
func AddOptFlag ¶
AddOptFlag adds the option to the flagSet, which is flag.CommandLine by default.
Notice: for the slice option, it maybe occur many times, and they are combined with the comma as the string representation of slice. For example,
$APP --slice-opt v1 --slice-opt v2 --slice-opt v3
They are equivalent.
func GetDuration ¶
GetDuration is equal to Conf.GetDuration(name).
func GetDurationSlice ¶
GetDurationSlice is equal to Conf.GetDurationSlice(name).
func GetFloat64 ¶
GetFloat64 is equal to Conf.GetFloat64(name).
func GetFloat64Slice ¶
GetFloat64Slice is equal to Conf.GetFloat64Slice(name).
func GetIntSlice ¶
GetIntSlice is equal to Conf.GetIntSlice(name).
func GetStringSlice ¶
GetStringSlice is equal to Conf.GetStringSlice(name).
func GetUintSlice ¶
GetUintSlice is equal to Conf.GetUintSlice(name).
func LoadAndWatchSource ¶
LoadAndWatchSource is equal to Conf.LoadAndWatchSource(source, force...).
func LoadBackupFile ¶
LoadBackupFile is equal to Conf.LoadBackupFile().
func LoadDataSet ¶
LoadDataSet is equal to Conf.LoadDataSet(source, force...).
func LoadSource ¶
LoadSource is equal to Conf.LoadSource(source, force...).
func PrintFlagUsage ¶
PrintFlagUsage prints the flag usage instead of the default.
func RegisterOpts ¶
func RegisterOpts(opts ...Opt)
RegisterOpts is equal to Conf.RegisterOpts(opts...).
func UnregisterOpts ¶
func UnregisterOpts(optNames ...string)
UnregisterOpts is equal to Conf.UnregisterOpts(optNames...).
Types ¶
type Config ¶
type Config struct { // Args is the CLI rest arguments. // // Default: nil Args []string // Version is the version of the application, which is used by CLI. Version Opt // Errorf is used to log the error. // // Default: log.Printf Errorf func(format string, args ...interface{}) // contains filtered or unexported fields }
Config is used to manage the configuration options.
func New ¶
func New() *Config
New returns a new Config with the "json", "yaml/yml" and "ini" decoder.
func (*Config) AddDecoder ¶
AddDecoder adds a decoder, which will override it if it has been added.s
func (*Config) AddDecoderTypeAliases ¶
AddDecoderTypeAliases adds the aliases of the decoder typed _type.
For example,
c.AddDecoderTypeAliases("yaml", "yml")
When acquiring the "yml" decoder and it does not exist, it will try to return the "yaml" decoder.
func (*Config) Get ¶
Get returns the value of the option named name.
Return nil if this option does not exist.
func (*Config) GetAllOpts ¶
GetAllOpts returns all the registered options.
func (*Config) GetDecoder ¶
GetDecoder returns the decoder by the type.
Return nil if the decoder does not exist.
func (*Config) GetDuration ¶
GetDuration returns the value of the option named name as time.Duration.
func (*Config) GetDurationSlice ¶
GetDurationSlice returns the value of the option named name as []time.Duration.
func (*Config) GetFloat64 ¶
GetFloat64 returns the value of the option named name as float64.
func (*Config) GetFloat64Slice ¶
GetFloat64Slice returns the value of the option named name as []float64.
func (*Config) GetGroupSep ¶
GetGroupSep returns the separator between the option groups.
func (*Config) GetInt16 ¶ added in v6.1.0
GetInt16 returns the value of the option named name as int16.
func (*Config) GetIntSlice ¶
GetIntSlice returns the value of the option named name as []int.
func (*Config) GetStringSlice ¶
GetStringSlice returns the value of the option named name as []string.
func (*Config) GetUint16 ¶ added in v6.1.0
GetUint16 returns the value of the option named name as uint16.
func (*Config) GetUintSlice ¶
GetUintSlice returns the value of the option named name as []uint.
func (*Config) IgnoreNoOptError ¶
IgnoreNoOptError sets whether to ignore the error NoOptError when updating the value of the option.
func (*Config) LoadAndWatchSource ¶
LoadAndWatchSource is the same as LoadSource, but also watches the source after loading the source successfully.
func (*Config) LoadBackupFile ¶
LoadBackupFile loads configuration data from the backup file if exists, then watches the change of the options and write them into the file. So you can use it as the local cache.
func (*Config) LoadDataSet ¶
LoadDataSet loads the DataSet ds, which will parse the data by calling the corresponding decoder and load it.
If failing to parse the value of any option, it terminates to parse and load it.
If force is missing or false, ignore the assigned options.
func (*Config) LoadMap ¶
LoadMap updates a set of the options together, but terminates to parse and load all if failing to parse the value of any option.
If force is missing or false, ignore the assigned options.
func (*Config) LoadSource ¶
LoadSource loads the options from the given source.
If force is missing or false, ignore the assigned options.
func (*Config) NewBool ¶
func (c *Config) NewBool(name string, _default bool, help string) *OptProxyBool
NewBool creates and registers a bool option, then returns its proxy.
func (*Config) NewDuration ¶
NewDuration creates and registers a time.Duration option, then returns its proxy.
func (*Config) NewDurationSlice ¶
func (c *Config) NewDurationSlice(name string, _default []time.Duration, help string) *OptProxyDurationSlice
NewDurationSlice creates and registers a []time.Duration option, then returns its proxy.
func (*Config) NewFloat64 ¶
func (c *Config) NewFloat64(name string, _default float64, help string) *OptProxyFloat64
NewFloat64 creates and registers a float64 option, then returns its proxy.
func (*Config) NewFloat64Slice ¶
func (c *Config) NewFloat64Slice(name string, _default []float64, help string) *OptProxyFloat64Slice
NewFloat64Slice creates and registers a []float64 option, then returns its proxy.
func (*Config) NewInt ¶
func (c *Config) NewInt(name string, _default int, help string) *OptProxyInt
NewInt creates and registers an int option, then returns its proxy.
func (*Config) NewInt16 ¶ added in v6.1.0
func (c *Config) NewInt16(name string, _default int16, help string) *OptProxyInt16
NewInt16 creates and registers a int16 option, then returns its proxy.
func (*Config) NewInt32 ¶
func (c *Config) NewInt32(name string, _default int32, help string) *OptProxyInt32
NewInt32 creates and registers a int32 option, then returns its proxy.
func (*Config) NewInt64 ¶
func (c *Config) NewInt64(name string, _default int64, help string) *OptProxyInt64
NewInt64 creates and registers a int64 option, then returns its proxy.
func (*Config) NewIntSlice ¶
func (c *Config) NewIntSlice(name string, _default []int, help string) *OptProxyIntSlice
NewIntSlice creates and registers a []int option, then returns its proxy.
func (*Config) NewOptProxy ¶
NewOptProxy registers the option and returns a new proxy of the option.
func (*Config) NewString ¶
func (c *Config) NewString(name, _default, help string) *OptProxyString
NewString creates and registers a string option, then returns its proxy.
func (*Config) NewStringSlice ¶
func (c *Config) NewStringSlice(name string, _default []string, help string) *OptProxyStringSlice
NewStringSlice creates and registers a []string option, then returns its proxy.
func (*Config) NewUint ¶
func (c *Config) NewUint(name string, _default uint, help string) *OptProxyUint
NewUint creates and registers a uint option, then returns its proxy.
func (*Config) NewUint16 ¶ added in v6.1.0
func (c *Config) NewUint16(name string, _default uint16, help string) *OptProxyUint16
NewUint16 creates and registers a uint16 option, then returns its proxy.
func (*Config) NewUint32 ¶
func (c *Config) NewUint32(name string, _default uint32, help string) *OptProxyUint32
NewUint32 creates and registers a uint32 option, then returns its proxy.
func (*Config) NewUint64 ¶
func (c *Config) NewUint64(name string, _default uint64, help string) *OptProxyUint64
NewUint64 creates and registers a uint64 option, then returns its proxy.
func (*Config) NewUintSlice ¶
func (c *Config) NewUintSlice(name string, _default []uint, help string) *OptProxyUintSlice
NewUintSlice creates and registers a []uint option, then returns its proxy.
func (*Config) Observe ¶
Observe appends the observers to watch the change of all the option values.
func (*Config) OptIsSet ¶
OptIsSet reports whether the option named name is set.
Return false if the option does not exist.
func (*Config) RegisterOpts ¶
RegisterOpts registers a set of options.
Notice: if a certain option has existed, it will panic.
func (*Config) SetVersion ¶
SetVersion sets the version information.
func (*Config) Snapshot ¶
Snapshot returns the snapshot of all the options and its generation which will increase with 1 each time any option value is changed.
For example,
map[string]interface{} { "opt1": "value1", "opt2": "value2", "group1.opt3": "value3", "group1.group2.opt4": "value4", // ... }
func (*Config) UnregisterOpts ¶
UnregisterOpts unregisters the registered options.
type DataSet ¶
type DataSet struct { Args []string // The CLI arguments filled by the CLI source such as flag. Data []byte // The original data. Format string // Such as "json", "xml", etc. Source string // Such as "file:/path/to/file", "zk:127.0.0.1:2181", etc. Checksum string // Such as "md5:7d2f31e6fff478337478413ee1b70d2a", etc. Timestamp time.Time // The timestamp when the data is modified. }
DataSet represents the information of the configuration data.
type Decoder ¶
Decoder is used to decode the configuration data.
func NewIniDecoder ¶
NewIniDecoder returns a INI decoder to decode the INI data.
Notice:
- The empty line will be ignored.
- The spacewhite on the beginning and end of line or value will be trimmed.
- The comment line starts with the character '#' or ';', which is ignored.
- The name of the default group is "DEFAULT", but it is optional.
- The group can nest other groups by ".", such as "group1.group2.group3".
- The key must only contain the printable non-spacewhite characters.
- The line can continue to the next line with the last character "\", and the spacewhite on the beginning and end of the each line will be trimmed, then combines them with a space.
func NewJSONDecoder ¶
func NewJSONDecoder() Decoder
NewJSONDecoder returns a json decoder to decode the json data.
If the json data contains the comment line starting with "//", it will remove the comment line and parse the json data.
Example ¶
data := []byte(`{ // user name "name": "Aaron", "age": 123, // the other information "other": { // address "home": "http://www.example.com" } }`) ms := make(map[string]interface{}) err := NewJSONDecoder()(data, ms) fmt.Println(err) fmt.Println(len(ms)) fmt.Println(ms["name"]) fmt.Println(ms["age"]) fmt.Println(ms["other"])
Output: <nil> 3 Aaron 123 map[home:http://www.example.com]
type Observer ¶
type Observer func(optName string, oldValue, newValue interface{})
Observer is used to observe the change of the option value.
type Opt ¶
type Opt struct { // Name is the long name of the option, which should be lower case. // // Required! Name string // Default is the default value of the option, which will be used to // indicate the type of the option. // // Required! Default interface{} // Parser is used to parse the input option value to a specific type. // // Required! Parser Parser // Short is the short name of the option, which should be a single- // character string, such as "v" for "version". // // Optional? Short string // Help is the help or usage information. // // Optional? Help string // IsCli indicates whether the option can be used for the CLI flag. // // Optional? IsCli bool // The list of the aliases of the option. // // Optional? Aliases []string // Validators is used to validate whether the option value is valid // after parsing it and before updating it. // // Optional? Validators []Validator // OnUpdate is called when the option value is updated. OnUpdate func(oldValue, newValue interface{}) }
Opt is used to represent a option vlaue.
func DurationOpt ¶
DurationOpt is the same NewOpt, but uses ToDuration to parse the value as time.Duration.
func DurationSliceOpt ¶
DurationSliceOpt is the same NewOpt, but uses ToDurationSlice to parse the value as []time.Duration.
func Float64Opt ¶
Float64Opt is the same NewOpt, but uses ToFloat64 to parse the value as float64.
func Float64SliceOpt ¶
Float64SliceOpt is the same NewOpt, but uses ToFloat64Slice to parse the value as []float64.
func Int16Opt ¶ added in v6.1.0
Int16Opt is the same NewOpt, but uses ToInt16 to parse the value as int16.
func IntSliceOpt ¶
IntSliceOpt is the same NewOpt, but uses ToIntSlice to parse the value as []int.
func StrSliceOpt ¶
StrSliceOpt is the same NewOpt, but uses ToStringSlice to parse the value as []string.
func Uint16Opt ¶ added in v6.1.0
Uint16Opt is the same NewOpt, but uses ToUint16 to parse the value as uint16.
func UintSliceOpt ¶
UintSliceOpt is the same NewOpt, but uses ToUintSlice to parse the value as []uint.
func (Opt) As ¶
As returns a new Opt with the new aliases based on the current option, which will append them.
type OptGroup ¶
type OptGroup struct {
// contains filtered or unexported fields
}
OptGroup is the proxy for a group of options.
func (*OptGroup) Get ¶
Get returns the value of the option named name.
Return nil if this option does not exist.
func (*OptGroup) GetAllOpts ¶ added in v6.2.0
GetAllOpts returns all the registered options in the group.
func (*OptGroup) GetDuration ¶
GetDuration returns the value of the option named name as time.Duration.
func (*OptGroup) GetDurationSlice ¶
GetDurationSlice returns the value of the option named name as []time.Duration.
func (*OptGroup) GetFloat64 ¶
GetFloat64 returns the value of the option named name as float64.
func (*OptGroup) GetFloat64Slice ¶
GetFloat64Slice returns the value of the option named name as []float64.
func (*OptGroup) GetInt16 ¶ added in v6.1.0
GetInt16 returns the value of the option named name as int16.
func (*OptGroup) GetIntSlice ¶
GetIntSlice returns the value of the option named name as []int.
func (*OptGroup) GetOpt ¶ added in v6.2.0
GetOpt returns the registered option by the name from the current group.
func (*OptGroup) GetStringSlice ¶
GetStringSlice returns the value of the option named name as []string.
func (*OptGroup) GetUint16 ¶ added in v6.1.0
GetUint16 returns the value of the option named name as uint16.
func (*OptGroup) GetUintSlice ¶
GetUintSlice returns the value of the option named name as []uint.
func (*OptGroup) HasOpt ¶ added in v6.2.0
HasOpt reports whether the option named name has been registered into the group.
func (*OptGroup) NewBool ¶
func (g *OptGroup) NewBool(name string, _default bool, help string) *OptProxyBool
NewBool creates and registers a bool option, then returns its proxy.
func (*OptGroup) NewDuration ¶
NewDuration creates and registers a time.Duration option, then returns its proxy.
func (*OptGroup) NewDurationSlice ¶
func (g *OptGroup) NewDurationSlice(name string, _default []time.Duration, help string) *OptProxyDurationSlice
NewDurationSlice creates and registers a []time.Duration option, then returns its proxy.
func (*OptGroup) NewFloat64 ¶
func (g *OptGroup) NewFloat64(name string, _default float64, help string) *OptProxyFloat64
NewFloat64 creates and registers a float64 option, then returns its proxy.
func (*OptGroup) NewFloat64Slice ¶
func (g *OptGroup) NewFloat64Slice(name string, _default []float64, help string) *OptProxyFloat64Slice
NewFloat64Slice creates and registers a []float64 option, then returns its proxy.
func (*OptGroup) NewInt ¶
func (g *OptGroup) NewInt(name string, _default int, help string) *OptProxyInt
NewInt creates and registers an int option, then returns its proxy.
func (*OptGroup) NewInt16 ¶ added in v6.1.0
func (g *OptGroup) NewInt16(name string, _default int16, help string) *OptProxyInt16
NewInt16 creates and registers a int16 option, then returns its proxy.
func (*OptGroup) NewInt32 ¶
func (g *OptGroup) NewInt32(name string, _default int32, help string) *OptProxyInt32
NewInt32 creates and registers a int32 option, then returns its proxy.
func (*OptGroup) NewInt64 ¶
func (g *OptGroup) NewInt64(name string, _default int64, help string) *OptProxyInt64
NewInt64 creates and registers a int64 option, then returns its proxy.
func (*OptGroup) NewIntSlice ¶
func (g *OptGroup) NewIntSlice(name string, _default []int, help string) *OptProxyIntSlice
NewIntSlice creates and registers a []int option, then returns its proxy.
func (*OptGroup) NewOptProxy ¶
NewOptProxy registers the option and returns a new proxy of the option.
func (*OptGroup) NewString ¶
func (g *OptGroup) NewString(name, _default, help string) *OptProxyString
NewString creates and registers a string option, then returns its proxy.
func (*OptGroup) NewStringSlice ¶
func (g *OptGroup) NewStringSlice(name string, _default []string, help string) *OptProxyStringSlice
NewStringSlice creates and registers a []string option, then returns its proxy.
func (*OptGroup) NewTime ¶
NewTime creates and registers a time.Time option, then returns its proxy.
func (*OptGroup) NewUint ¶
func (g *OptGroup) NewUint(name string, _default uint, help string) *OptProxyUint
NewUint is equal to Conf.NewUint(name, _default, help).
func (*OptGroup) NewUint16 ¶ added in v6.1.0
func (g *OptGroup) NewUint16(name string, _default uint16, help string) *OptProxyUint16
NewUint16 creates and registers a uint16 option, then returns its proxy.
func (*OptGroup) NewUint32 ¶
func (g *OptGroup) NewUint32(name string, _default uint32, help string) *OptProxyUint32
NewUint32 creates and registers a uint32 option, then returns its proxy.
func (*OptGroup) NewUint64 ¶
func (g *OptGroup) NewUint64(name string, _default uint64, help string) *OptProxyUint64
NewUint64 creates and registers a uint64 option, then returns its proxy.
func (*OptGroup) NewUintSlice ¶
func (g *OptGroup) NewUintSlice(name string, _default []uint, help string) *OptProxyUintSlice
NewUintSlice creates and registers a []uint option, then returns its proxy.
func (*OptGroup) OptIsSet ¶ added in v6.2.0
OptIsSet reports whether the option named name in the group is set.
Return false if the option does not exist.
func (*OptGroup) RegisterOpts ¶
RegisterOpts registers a set of options.
Notice: if a certain option has existed, it will panic.
func (*OptGroup) SelfBool ¶
func (g *OptGroup) SelfBool(help string) *OptProxyBool
SelfBool makes itself into a bool option proxy with the default value "false".
func (*OptGroup) UnregisterOpts ¶
UnregisterOpts unregisters the registered options.
type OptProxy ¶
type OptProxy struct {
// contains filtered or unexported fields
}
OptProxy is a proxy for the option registered into Config, which can be used to modify the attributions of the option and update its value directly.
func NewOptProxy ¶
NewOptProxy registers the option into c and returns a proxy of opt.
func (*OptProxy) OnUpdate ¶
OnUpdate resets the update callback function of the option and returns itself.
func (OptProxy) ToBool ¶ added in v6.1.0
func (o OptProxy) ToBool() *OptProxyBool
ToBool converts option from OptProxy to OptProxyBool.
func (OptProxy) ToDuration ¶ added in v6.1.0
func (o OptProxy) ToDuration() *OptProxyDuration
ToDuration converts option from OptProxy to OptProxyDuration.
func (OptProxy) ToDurationSlice ¶ added in v6.1.0
func (o OptProxy) ToDurationSlice() *OptProxyDurationSlice
ToDurationSlice converts option from OptProxy to OptProxyDurationSlice.
func (OptProxy) ToFloat64 ¶ added in v6.1.0
func (o OptProxy) ToFloat64() *OptProxyFloat64
ToFloat64 converts option from OptProxy to OptProxyFloat64.
func (OptProxy) ToFloat64Slice ¶ added in v6.1.0
func (o OptProxy) ToFloat64Slice() *OptProxyFloat64Slice
ToFloat64Slice converts option from OptProxy to OptProxyFloat64Slice.
func (OptProxy) ToInt ¶ added in v6.1.0
func (o OptProxy) ToInt() *OptProxyInt
ToInt converts option from OptProxy to OptProxyInt.
func (OptProxy) ToInt16 ¶ added in v6.1.0
func (o OptProxy) ToInt16() *OptProxyInt16
ToInt16 converts option from OptProxy to OptProxyInt16.
func (OptProxy) ToInt32 ¶ added in v6.1.0
func (o OptProxy) ToInt32() *OptProxyInt32
ToInt32 converts option from OptProxy to OptProxyInt32.
func (OptProxy) ToInt64 ¶ added in v6.1.0
func (o OptProxy) ToInt64() *OptProxyInt64
ToInt64 converts option from OptProxy to OptProxyInt64.
func (OptProxy) ToIntSlice ¶ added in v6.1.0
func (o OptProxy) ToIntSlice() *OptProxyIntSlice
ToIntSlice converts option from OptProxy to OptProxyIntSlice.
func (OptProxy) ToString ¶ added in v6.1.0
func (o OptProxy) ToString() *OptProxyString
ToString converts option from OptProxy to OptProxyString.
func (OptProxy) ToStringSlice ¶ added in v6.1.0
func (o OptProxy) ToStringSlice() *OptProxyStringSlice
ToStringSlice converts option from OptProxy to OptProxyStringSlice.
func (OptProxy) ToTime ¶ added in v6.1.0
func (o OptProxy) ToTime() *OptProxyTime
ToTime converts option from OptProxy to OptProxyTime.
func (OptProxy) ToUint ¶ added in v6.1.0
func (o OptProxy) ToUint() *OptProxyUint
ToUint converts option from OptProxy to OptProxyUint.
func (OptProxy) ToUint16 ¶ added in v6.1.0
func (o OptProxy) ToUint16() *OptProxyUint16
ToUint16 converts option from OptProxy to OptProxyUint16.
func (OptProxy) ToUint32 ¶ added in v6.1.0
func (o OptProxy) ToUint32() *OptProxyUint32
ToUint32 converts option from OptProxy to OptProxyUint32.
func (OptProxy) ToUint64 ¶ added in v6.1.0
func (o OptProxy) ToUint64() *OptProxyUint64
ToUint64 converts option from OptProxy to OptProxyUint64.
func (OptProxy) ToUintSlice ¶ added in v6.1.0
func (o OptProxy) ToUintSlice() *OptProxyUintSlice
ToUintSlice converts option from OptProxy to OptProxyUintSlice.
func (*OptProxy) Validators ¶
Validators appends the validators of the option and returns itself.
type OptProxyBool ¶
type OptProxyBool struct{ OptProxy }
OptProxyBool is a proxy for the bool option registered into Config, which can be used to modify the attributions of the option and update its value directly.
func NewBool ¶
func NewBool(name string, _default bool, help string) *OptProxyBool
NewBool is equal to Conf.NewBool(name, _default, help).
func (*OptProxyBool) Aliases ¶
func (o *OptProxyBool) Aliases(aliases ...string) *OptProxyBool
Aliases appends the aliases of the option and returns itself.
func (*OptProxyBool) Default ¶
func (o *OptProxyBool) Default(_default interface{}) *OptProxyBool
Default resets the default value of the option and returns itself.
func (*OptProxyBool) IsCli ¶
func (o *OptProxyBool) IsCli(cli bool) *OptProxyBool
IsCli resets the cli flag of the option and returns itself.
func (*OptProxyBool) Name ¶
func (o *OptProxyBool) Name() string
Name returns the name of the option.
func (*OptProxyBool) OnUpdate ¶
func (o *OptProxyBool) OnUpdate(f func(old, new interface{})) *OptProxyBool
OnUpdate resets the update callback of the option and returns itself.
func (*OptProxyBool) Opt ¶
func (o *OptProxyBool) Opt() Opt
Opt returns the registered and proxied option.
func (*OptProxyBool) Parser ¶
func (o *OptProxyBool) Parser(parser Parser) *OptProxyBool
Parser resets the parser of the option and returns itself.
func (*OptProxyBool) Set ¶
func (o *OptProxyBool) Set(value interface{}) (err error)
Set sets the value of the option to value.
func (*OptProxyBool) Short ¶
func (o *OptProxyBool) Short(short string) *OptProxyBool
Short resets the short name of the option and returns itself.
func (*OptProxyBool) Validators ¶
func (o *OptProxyBool) Validators(validators ...Validator) *OptProxyBool
Validators appends the validators of the option and returns itself.
type OptProxyDuration ¶
type OptProxyDuration struct{ OptProxy }
OptProxyDuration is a proxy for the time.Duration option registered into Config, which can be used to modify the attributions of the option and update its value directly.
func NewDuration ¶
func NewDuration(name string, _default time.Duration, help string) *OptProxyDuration
NewDuration is equal to Conf.NewDuration(name, _default, help).
func (*OptProxyDuration) Aliases ¶
func (o *OptProxyDuration) Aliases(aliases ...string) *OptProxyDuration
Aliases appends the aliases of the option and returns itself.
func (*OptProxyDuration) Default ¶
func (o *OptProxyDuration) Default(_default interface{}) *OptProxyDuration
Default resets the default value of the option and returns itself.
func (*OptProxyDuration) Get ¶
func (o *OptProxyDuration) Get() time.Duration
Get returns the value of the option.
func (*OptProxyDuration) IsCli ¶
func (o *OptProxyDuration) IsCli(cli bool) *OptProxyDuration
IsCli resets the cli flag of the option and returns itself.
func (*OptProxyDuration) Name ¶
func (o *OptProxyDuration) Name() string
Name returns the name of the option.
func (*OptProxyDuration) OnUpdate ¶
func (o *OptProxyDuration) OnUpdate(f func(old, new interface{})) *OptProxyDuration
OnUpdate resets the update callback of the option and returns itself.
func (*OptProxyDuration) Opt ¶
func (o *OptProxyDuration) Opt() Opt
Opt returns the registered and proxied option.
func (*OptProxyDuration) Parser ¶
func (o *OptProxyDuration) Parser(parser Parser) *OptProxyDuration
Parser resets the parser of the option and returns itself.
func (*OptProxyDuration) Set ¶
func (o *OptProxyDuration) Set(value interface{}) (err error)
Set sets the value of the option to value.
func (*OptProxyDuration) Short ¶
func (o *OptProxyDuration) Short(short string) *OptProxyDuration
Short resets the short name of the option and returns itself.
func (*OptProxyDuration) Validators ¶
func (o *OptProxyDuration) Validators(validators ...Validator) *OptProxyDuration
Validators appends the validators of the option and returns itself.
type OptProxyDurationSlice ¶
type OptProxyDurationSlice struct{ OptProxy }
OptProxyDurationSlice is a proxy for the []time.Duration option registered into Config, which can be used to modify the attributions of the option and update its value directly.
func NewDurationSlice ¶
func NewDurationSlice(name string, _default []time.Duration, help string) *OptProxyDurationSlice
NewDurationSlice is equal to Conf.NewDurationSlice(name, _default, help).
func (*OptProxyDurationSlice) Aliases ¶
func (o *OptProxyDurationSlice) Aliases(aliases ...string) *OptProxyDurationSlice
Aliases appends the aliases of the option and returns itself.
func (*OptProxyDurationSlice) Default ¶
func (o *OptProxyDurationSlice) Default(_default interface{}) *OptProxyDurationSlice
Default resets the default value of the option and returns itself.
func (*OptProxyDurationSlice) Get ¶
func (o *OptProxyDurationSlice) Get() []time.Duration
Get returns the value of the option.
func (*OptProxyDurationSlice) IsCli ¶
func (o *OptProxyDurationSlice) IsCli(cli bool) *OptProxyDurationSlice
IsCli resets the cli flag of the option and returns itself.
func (*OptProxyDurationSlice) Name ¶
func (o *OptProxyDurationSlice) Name() string
Name returns the name of the option.
func (*OptProxyDurationSlice) OnUpdate ¶
func (o *OptProxyDurationSlice) OnUpdate(f func(old, new interface{})) *OptProxyDurationSlice
OnUpdate resets the update callback of the option and returns itself.
func (*OptProxyDurationSlice) Opt ¶
func (o *OptProxyDurationSlice) Opt() Opt
Opt returns the registered and proxied option.
func (*OptProxyDurationSlice) Parser ¶
func (o *OptProxyDurationSlice) Parser(parser Parser) *OptProxyDurationSlice
Parser resets the parser of the option and returns itself.
func (*OptProxyDurationSlice) Set ¶
func (o *OptProxyDurationSlice) Set(value interface{}) (err error)
Set sets the value of the option to value.
func (*OptProxyDurationSlice) Short ¶
func (o *OptProxyDurationSlice) Short(short string) *OptProxyDurationSlice
Short resets the short name of the option and returns itself.
func (*OptProxyDurationSlice) Validators ¶
func (o *OptProxyDurationSlice) Validators(validators ...Validator) *OptProxyDurationSlice
Validators appends the validators of the option and returns itself.
type OptProxyFloat64 ¶
type OptProxyFloat64 struct{ OptProxy }
OptProxyFloat64 is a proxy for the float64 option registered into Config, which can be used to modify the attributions of the option and update its value directly.
func NewFloat64 ¶
func NewFloat64(name string, _default float64, help string) *OptProxyFloat64
NewFloat64 is equal to Conf.NewFloat64(name, _default, help).
func (*OptProxyFloat64) Aliases ¶
func (o *OptProxyFloat64) Aliases(aliases ...string) *OptProxyFloat64
Aliases appends the aliases of the option and returns itself.
func (*OptProxyFloat64) Default ¶
func (o *OptProxyFloat64) Default(_default interface{}) *OptProxyFloat64
Default resets the default value of the option and returns itself.
func (*OptProxyFloat64) Get ¶
func (o *OptProxyFloat64) Get() float64
Get returns the value of the option.
func (*OptProxyFloat64) IsCli ¶
func (o *OptProxyFloat64) IsCli(cli bool) *OptProxyFloat64
IsCli resets the cli flag of the option and returns itself.
func (*OptProxyFloat64) Name ¶
func (o *OptProxyFloat64) Name() string
Name returns the name of the option.
func (*OptProxyFloat64) OnUpdate ¶
func (o *OptProxyFloat64) OnUpdate(f func(old, new interface{})) *OptProxyFloat64
OnUpdate resets the update callback of the option and returns itself.
func (*OptProxyFloat64) Opt ¶
func (o *OptProxyFloat64) Opt() Opt
Opt returns the registered and proxied option.
func (*OptProxyFloat64) Parser ¶
func (o *OptProxyFloat64) Parser(parser Parser) *OptProxyFloat64
Parser resets the parser of the option and returns itself.
func (*OptProxyFloat64) Set ¶
func (o *OptProxyFloat64) Set(value interface{}) (err error)
Set sets the value of the option to value.
func (*OptProxyFloat64) Short ¶
func (o *OptProxyFloat64) Short(short string) *OptProxyFloat64
Short resets the short name of the option and returns itself.
func (*OptProxyFloat64) Validators ¶
func (o *OptProxyFloat64) Validators(validators ...Validator) *OptProxyFloat64
Validators appends the validators of the option and returns itself.
type OptProxyFloat64Slice ¶
type OptProxyFloat64Slice struct{ OptProxy }
OptProxyFloat64Slice is a proxy for the []float64 option registered into Config, which can be used to modify the attributions of the option and update its value directly.
func NewFloat64Slice ¶
func NewFloat64Slice(name string, _default []float64, help string) *OptProxyFloat64Slice
NewFloat64Slice is equal to Conf.NewFloat64Slice(name, _default, help).
func (*OptProxyFloat64Slice) Aliases ¶
func (o *OptProxyFloat64Slice) Aliases(aliases ...string) *OptProxyFloat64Slice
Aliases appends the aliases of the option and returns itself.
func (*OptProxyFloat64Slice) Default ¶
func (o *OptProxyFloat64Slice) Default(_default interface{}) *OptProxyFloat64Slice
Default resets the default value of the option and returns itself.
func (*OptProxyFloat64Slice) Get ¶
func (o *OptProxyFloat64Slice) Get() []float64
Get returns the value of the option.
func (*OptProxyFloat64Slice) IsCli ¶
func (o *OptProxyFloat64Slice) IsCli(cli bool) *OptProxyFloat64Slice
IsCli resets the cli flag of the option and returns itself.
func (*OptProxyFloat64Slice) Name ¶
func (o *OptProxyFloat64Slice) Name() string
Name returns the name of the option.
func (*OptProxyFloat64Slice) OnUpdate ¶
func (o *OptProxyFloat64Slice) OnUpdate(f func(old, new interface{})) *OptProxyFloat64Slice
OnUpdate resets the update callback of the option and returns itself.
func (*OptProxyFloat64Slice) Opt ¶
func (o *OptProxyFloat64Slice) Opt() Opt
Opt returns the registered and proxied option.
func (*OptProxyFloat64Slice) Parser ¶
func (o *OptProxyFloat64Slice) Parser(parser Parser) *OptProxyFloat64Slice
Parser resets the parser of the option and returns itself.
func (*OptProxyFloat64Slice) Set ¶
func (o *OptProxyFloat64Slice) Set(value interface{}) (err error)
Set sets the value of the option to value.
func (*OptProxyFloat64Slice) Short ¶
func (o *OptProxyFloat64Slice) Short(short string) *OptProxyFloat64Slice
Short resets the short name of the option and returns itself.
func (*OptProxyFloat64Slice) Validators ¶
func (o *OptProxyFloat64Slice) Validators(validators ...Validator) *OptProxyFloat64Slice
Validators appends the validators of the option and returns itself.
type OptProxyInt ¶
type OptProxyInt struct{ OptProxy }
OptProxyInt is a proxy for the int option registered into Config, which can be used to modify the attributions of the option and update its value directly.
func NewInt ¶
func NewInt(name string, _default int, help string) *OptProxyInt
NewInt is equal to Conf.NewInt(name, _default, help).
func (*OptProxyInt) Aliases ¶
func (o *OptProxyInt) Aliases(aliases ...string) *OptProxyInt
Aliases appends the aliases of the option and returns itself.
func (*OptProxyInt) Default ¶
func (o *OptProxyInt) Default(_default interface{}) *OptProxyInt
Default resets the default value of the option and returns itself.
func (*OptProxyInt) IsCli ¶
func (o *OptProxyInt) IsCli(cli bool) *OptProxyInt
IsCli resets the cli flag of the option and returns itself.
func (*OptProxyInt) OnUpdate ¶
func (o *OptProxyInt) OnUpdate(f func(old, new interface{})) *OptProxyInt
OnUpdate resets the update callback of the option and returns itself.
func (*OptProxyInt) Opt ¶
func (o *OptProxyInt) Opt() Opt
Opt returns the registered and proxied option.
func (*OptProxyInt) Parser ¶
func (o *OptProxyInt) Parser(parser Parser) *OptProxyInt
Parser resets the parser of the option and returns itself.
func (*OptProxyInt) Set ¶
func (o *OptProxyInt) Set(value interface{}) (err error)
Set sets the value of the option to value.
func (*OptProxyInt) Short ¶
func (o *OptProxyInt) Short(short string) *OptProxyInt
Short resets the short name of the option and returns itself.
func (*OptProxyInt) Validators ¶
func (o *OptProxyInt) Validators(validators ...Validator) *OptProxyInt
Validators appends the validators of the option and returns itself.
type OptProxyInt16 ¶ added in v6.1.0
type OptProxyInt16 struct{ OptProxy }
OptProxyInt16 is a proxy for the int16 option registered into Config, which can be used to modify the attributions of the option and update its value directly.
func NewInt16 ¶ added in v6.1.0
func NewInt16(name string, _default int16, help string) *OptProxyInt16
NewInt16 is equal to Conf.NewInt16(name, _default, help).
func (*OptProxyInt16) Aliases ¶ added in v6.1.0
func (o *OptProxyInt16) Aliases(aliases ...string) *OptProxyInt16
Aliases appends the aliases of the option and returns itself.
func (*OptProxyInt16) Default ¶ added in v6.1.0
func (o *OptProxyInt16) Default(_default interface{}) *OptProxyInt16
Default resets the default value of the option and returns itself.
func (*OptProxyInt16) Get ¶ added in v6.1.0
func (o *OptProxyInt16) Get() int16
Get returns the value of the option.
func (*OptProxyInt16) IsCli ¶ added in v6.1.0
func (o *OptProxyInt16) IsCli(cli bool) *OptProxyInt16
IsCli resets the cli flag of the option and returns itself.
func (*OptProxyInt16) Name ¶ added in v6.1.0
func (o *OptProxyInt16) Name() string
Name returns the name of the option.
func (*OptProxyInt16) OnUpdate ¶ added in v6.1.0
func (o *OptProxyInt16) OnUpdate(f func(old, new interface{})) *OptProxyInt16
OnUpdate resets the update callback of the option and returns itself.
func (*OptProxyInt16) Opt ¶ added in v6.1.0
func (o *OptProxyInt16) Opt() Opt
Opt returns the registered and proxied option.
func (*OptProxyInt16) Parser ¶ added in v6.1.0
func (o *OptProxyInt16) Parser(parser Parser) *OptProxyInt16
Parser resets the parser of the option and returns itself.
func (*OptProxyInt16) Set ¶ added in v6.1.0
func (o *OptProxyInt16) Set(value interface{}) (err error)
Set sets the value of the option to value.
func (*OptProxyInt16) Short ¶ added in v6.1.0
func (o *OptProxyInt16) Short(short string) *OptProxyInt16
Short resets the short name of the option and returns itself.
func (*OptProxyInt16) Validators ¶ added in v6.1.0
func (o *OptProxyInt16) Validators(validators ...Validator) *OptProxyInt16
Validators appends the validators of the option and returns itself.
type OptProxyInt32 ¶
type OptProxyInt32 struct{ OptProxy }
OptProxyInt32 is a proxy for the int32 option registered into Config, which can be used to modify the attributions of the option and update its value directly.
func NewInt32 ¶
func NewInt32(name string, _default int32, help string) *OptProxyInt32
NewInt32 is equal to Conf.NewInt32(name, _default, help).
func (*OptProxyInt32) Aliases ¶
func (o *OptProxyInt32) Aliases(aliases ...string) *OptProxyInt32
Aliases appends the aliases of the option and returns itself.
func (*OptProxyInt32) Default ¶
func (o *OptProxyInt32) Default(_default interface{}) *OptProxyInt32
Default resets the default value of the option and returns itself.
func (*OptProxyInt32) Get ¶
func (o *OptProxyInt32) Get() int32
Get returns the value of the option.
func (*OptProxyInt32) IsCli ¶
func (o *OptProxyInt32) IsCli(cli bool) *OptProxyInt32
IsCli resets the cli flag of the option and returns itself.
func (*OptProxyInt32) Name ¶
func (o *OptProxyInt32) Name() string
Name returns the name of the option.
func (*OptProxyInt32) OnUpdate ¶
func (o *OptProxyInt32) OnUpdate(f func(old, new interface{})) *OptProxyInt32
OnUpdate resets the update callback of the option and returns itself.
func (*OptProxyInt32) Opt ¶
func (o *OptProxyInt32) Opt() Opt
Opt returns the registered and proxied option.
func (*OptProxyInt32) Parser ¶
func (o *OptProxyInt32) Parser(parser Parser) *OptProxyInt32
Parser resets the parser of the option and returns itself.
func (*OptProxyInt32) Set ¶
func (o *OptProxyInt32) Set(value interface{}) (err error)
Set sets the value of the option to value.
func (*OptProxyInt32) Short ¶
func (o *OptProxyInt32) Short(short string) *OptProxyInt32
Short resets the short name of the option and returns itself.
func (*OptProxyInt32) Validators ¶
func (o *OptProxyInt32) Validators(validators ...Validator) *OptProxyInt32
Validators appends the validators of the option and returns itself.
type OptProxyInt64 ¶
type OptProxyInt64 struct{ OptProxy }
OptProxyInt64 is a proxy for the int64 option registered into Config, which can be used to modify the attributions of the option and update its value directly.
func NewInt64 ¶
func NewInt64(name string, _default int64, help string) *OptProxyInt64
NewInt64 is equal to Conf.NewInt64(name, _default, help).
func (*OptProxyInt64) Aliases ¶
func (o *OptProxyInt64) Aliases(aliases ...string) *OptProxyInt64
Aliases appends the aliases of the option and returns itself.
func (*OptProxyInt64) Default ¶
func (o *OptProxyInt64) Default(_default interface{}) *OptProxyInt64
Default resets the default value of the option and returns itself.
func (*OptProxyInt64) Get ¶
func (o *OptProxyInt64) Get() int64
Get returns the value of the option.
func (*OptProxyInt64) IsCli ¶
func (o *OptProxyInt64) IsCli(cli bool) *OptProxyInt64
IsCli resets the cli flag of the option and returns itself.
func (*OptProxyInt64) Name ¶
func (o *OptProxyInt64) Name() string
Name returns the name of the option.
func (*OptProxyInt64) OnUpdate ¶
func (o *OptProxyInt64) OnUpdate(f func(old, new interface{})) *OptProxyInt64
OnUpdate resets the update callback of the option and returns itself.
func (*OptProxyInt64) Opt ¶
func (o *OptProxyInt64) Opt() Opt
Opt returns the registered and proxied option.
func (*OptProxyInt64) Parser ¶
func (o *OptProxyInt64) Parser(parser Parser) *OptProxyInt64
Parser resets the parser of the option and returns itself.
func (*OptProxyInt64) Set ¶
func (o *OptProxyInt64) Set(value interface{}) (err error)
Set sets the value of the option to value.
func (*OptProxyInt64) Short ¶
func (o *OptProxyInt64) Short(short string) *OptProxyInt64
Short resets the short name of the option and returns itself.
func (*OptProxyInt64) Validators ¶
func (o *OptProxyInt64) Validators(validators ...Validator) *OptProxyInt64
Validators appends the validators of the option and returns itself.
type OptProxyIntSlice ¶
type OptProxyIntSlice struct{ OptProxy }
OptProxyIntSlice is a proxy for the []int option registered into Config, which can be used to modify the attributions of the option and update its value directly.
func NewIntSlice ¶
func NewIntSlice(name string, _default []int, help string) *OptProxyIntSlice
NewIntSlice is equal to Conf.NewIntSlice(name, _default, help).
func (*OptProxyIntSlice) Aliases ¶
func (o *OptProxyIntSlice) Aliases(aliases ...string) *OptProxyIntSlice
Aliases appends the aliases of the option and returns itself.
func (*OptProxyIntSlice) Default ¶
func (o *OptProxyIntSlice) Default(_default interface{}) *OptProxyIntSlice
Default resets the default value of the option and returns itself.
func (*OptProxyIntSlice) Get ¶
func (o *OptProxyIntSlice) Get() []int
Get returns the value of the option.
func (*OptProxyIntSlice) IsCli ¶
func (o *OptProxyIntSlice) IsCli(cli bool) *OptProxyIntSlice
IsCli resets the cli flag of the option and returns itself.
func (*OptProxyIntSlice) Name ¶
func (o *OptProxyIntSlice) Name() string
Name returns the name of the option.
func (*OptProxyIntSlice) OnUpdate ¶
func (o *OptProxyIntSlice) OnUpdate(f func(old, new interface{})) *OptProxyIntSlice
OnUpdate resets the update callback of the option and returns itself.
func (*OptProxyIntSlice) Opt ¶
func (o *OptProxyIntSlice) Opt() Opt
Opt returns the registered and proxied option.
func (*OptProxyIntSlice) Parser ¶
func (o *OptProxyIntSlice) Parser(parser Parser) *OptProxyIntSlice
Parser resets the parser of the option and returns itself.
func (*OptProxyIntSlice) Set ¶
func (o *OptProxyIntSlice) Set(value interface{}) (err error)
Set sets the value of the option to value.
func (*OptProxyIntSlice) Short ¶
func (o *OptProxyIntSlice) Short(short string) *OptProxyIntSlice
Short resets the short name of the option and returns itself.
func (*OptProxyIntSlice) Validators ¶
func (o *OptProxyIntSlice) Validators(validators ...Validator) *OptProxyIntSlice
Validators appends the validators of the option and returns itself.
type OptProxyString ¶
type OptProxyString struct{ OptProxy }
OptProxyString is a proxy for the string option registered into Config, which can be used to modify the attributions of the option and update its value directly.
func NewString ¶
func NewString(name, _default, help string) *OptProxyString
NewString is equal to Conf.NewString(name, _default, help).
func (*OptProxyString) Aliases ¶
func (o *OptProxyString) Aliases(aliases ...string) *OptProxyString
Aliases appends the aliases of the option and returns itself.
func (*OptProxyString) Default ¶
func (o *OptProxyString) Default(_default interface{}) *OptProxyString
Default resets the default value of the option and returns itself.
func (*OptProxyString) Get ¶
func (o *OptProxyString) Get() string
Get returns the value of the option.
func (*OptProxyString) IsCli ¶
func (o *OptProxyString) IsCli(cli bool) *OptProxyString
IsCli resets the cli flag of the option and returns itself.
func (*OptProxyString) Name ¶
func (o *OptProxyString) Name() string
Name returns the name of the option.
func (*OptProxyString) OnUpdate ¶
func (o *OptProxyString) OnUpdate(f func(old, new interface{})) *OptProxyString
OnUpdate resets the update callback of the option and returns itself.
func (*OptProxyString) Opt ¶
func (o *OptProxyString) Opt() Opt
Opt returns the registered and proxied option.
func (*OptProxyString) Parser ¶
func (o *OptProxyString) Parser(parser Parser) *OptProxyString
Parser resets the parser of the option and returns itself.
func (*OptProxyString) Set ¶
func (o *OptProxyString) Set(value interface{}) (err error)
Set sets the value of the option to value.
func (*OptProxyString) Short ¶
func (o *OptProxyString) Short(short string) *OptProxyString
Short resets the short name of the option and returns itself.
func (*OptProxyString) Validators ¶
func (o *OptProxyString) Validators(validators ...Validator) *OptProxyString
Validators appends the validators of the option and returns itself.
type OptProxyStringSlice ¶
type OptProxyStringSlice struct{ OptProxy }
OptProxyStringSlice is a proxy for the []string option registered into Config, which can be used to modify the attributions of the option and update its value directly.
func NewStringSlice ¶
func NewStringSlice(name string, _default []string, help string) *OptProxyStringSlice
NewStringSlice is equal to Conf.NewStringSlice(name, _default, help).
func (*OptProxyStringSlice) Aliases ¶
func (o *OptProxyStringSlice) Aliases(aliases ...string) *OptProxyStringSlice
Aliases appends the aliases of the option and returns itself.
func (*OptProxyStringSlice) Default ¶
func (o *OptProxyStringSlice) Default(_default interface{}) *OptProxyStringSlice
Default resets the default value of the option and returns itself.
func (*OptProxyStringSlice) Get ¶
func (o *OptProxyStringSlice) Get() []string
Get returns the value of the option.
func (*OptProxyStringSlice) IsCli ¶
func (o *OptProxyStringSlice) IsCli(cli bool) *OptProxyStringSlice
IsCli resets the cli flag of the option and returns itself.
func (*OptProxyStringSlice) Name ¶
func (o *OptProxyStringSlice) Name() string
Name returns the name of the option.
func (*OptProxyStringSlice) OnUpdate ¶
func (o *OptProxyStringSlice) OnUpdate(f func(old, new interface{})) *OptProxyStringSlice
OnUpdate resets the update callback of the option and returns itself.
func (*OptProxyStringSlice) Opt ¶
func (o *OptProxyStringSlice) Opt() Opt
Opt returns the registered and proxied option.
func (*OptProxyStringSlice) Parser ¶
func (o *OptProxyStringSlice) Parser(parser Parser) *OptProxyStringSlice
Parser resets the parser of the option and returns itself.
func (*OptProxyStringSlice) Set ¶
func (o *OptProxyStringSlice) Set(value interface{}) (err error)
Set sets the value of the option to value.
func (*OptProxyStringSlice) Short ¶
func (o *OptProxyStringSlice) Short(short string) *OptProxyStringSlice
Short resets the short name of the option and returns itself.
func (*OptProxyStringSlice) Validators ¶
func (o *OptProxyStringSlice) Validators(validators ...Validator) *OptProxyStringSlice
Validators appends the validators of the option and returns itself.
type OptProxyTime ¶
type OptProxyTime struct{ OptProxy }
OptProxyTime is a proxy for the time.Time option registered into Config, which can be used to modify the attributions of the option and update its value directly.
func NewTime ¶
func NewTime(name string, _default time.Time, help string) *OptProxyTime
NewTime is equal to Conf.NewTime(name, _default, help).
func (*OptProxyTime) Aliases ¶
func (o *OptProxyTime) Aliases(aliases ...string) *OptProxyTime
Aliases appends the aliases of the option and returns itself.
func (*OptProxyTime) Default ¶
func (o *OptProxyTime) Default(_default interface{}) *OptProxyTime
Default resets the default value of the option and returns itself.
func (*OptProxyTime) Get ¶
func (o *OptProxyTime) Get() time.Time
Get returns the value of the option.
func (*OptProxyTime) IsCli ¶
func (o *OptProxyTime) IsCli(cli bool) *OptProxyTime
IsCli resets the cli flag of the option and returns itself.
func (*OptProxyTime) Name ¶
func (o *OptProxyTime) Name() string
Name returns the name of the option.
func (*OptProxyTime) OnUpdate ¶
func (o *OptProxyTime) OnUpdate(f func(old, new interface{})) *OptProxyTime
OnUpdate resets the update callback of the option and returns itself.
func (*OptProxyTime) Opt ¶
func (o *OptProxyTime) Opt() Opt
Opt returns the registered and proxied option.
func (*OptProxyTime) Parser ¶
func (o *OptProxyTime) Parser(parser Parser) *OptProxyTime
Parser resets the parser of the option and returns itself.
func (*OptProxyTime) Set ¶
func (o *OptProxyTime) Set(value interface{}) (err error)
Set sets the value of the option to value.
func (*OptProxyTime) Short ¶
func (o *OptProxyTime) Short(short string) *OptProxyTime
Short resets the short name of the option and returns itself.
func (*OptProxyTime) Validators ¶
func (o *OptProxyTime) Validators(validators ...Validator) *OptProxyTime
Validators appends the validators of the option and returns itself.
type OptProxyUint ¶
type OptProxyUint struct{ OptProxy }
OptProxyUint is a proxy for the uint option registered into Config, which can be used to modify the attributions of the option and update its value directly.
func NewUint ¶
func NewUint(name string, _default uint, help string) *OptProxyUint
NewUint is equal to Conf.NewUint(name, _default, help).
func (*OptProxyUint) Aliases ¶
func (o *OptProxyUint) Aliases(aliases ...string) *OptProxyUint
Aliases appends the aliases of the option and returns itself.
func (*OptProxyUint) Default ¶
func (o *OptProxyUint) Default(_default interface{}) *OptProxyUint
Default resets the default value of the option and returns itself.
func (*OptProxyUint) IsCli ¶
func (o *OptProxyUint) IsCli(cli bool) *OptProxyUint
IsCli resets the cli flag of the option and returns itself.
func (*OptProxyUint) Name ¶
func (o *OptProxyUint) Name() string
Name returns the name of the option.
func (*OptProxyUint) OnUpdate ¶
func (o *OptProxyUint) OnUpdate(f func(old, new interface{})) *OptProxyUint
OnUpdate resets the update callback of the option and returns itself.
func (*OptProxyUint) Opt ¶
func (o *OptProxyUint) Opt() Opt
Opt returns the registered and proxied option.
func (*OptProxyUint) Parser ¶
func (o *OptProxyUint) Parser(parser Parser) *OptProxyUint
Parser resets the parser of the option and returns itself.
func (*OptProxyUint) Set ¶
func (o *OptProxyUint) Set(value interface{}) (err error)
Set sets the value of the option to value.
func (*OptProxyUint) Short ¶
func (o *OptProxyUint) Short(short string) *OptProxyUint
Short resets the short name of the option and returns itself.
func (*OptProxyUint) Validators ¶
func (o *OptProxyUint) Validators(validators ...Validator) *OptProxyUint
Validators appends the validators of the option and returns itself.
type OptProxyUint16 ¶ added in v6.1.0
type OptProxyUint16 struct{ OptProxy }
OptProxyUint16 is a proxy for the uint16 option registered into Config, which can be used to modify the attributions of the option and update its value directly.
func NewUint16 ¶ added in v6.1.0
func NewUint16(name string, _default uint16, help string) *OptProxyUint16
NewUint16 is equal to Conf.NewUint16(name, _default, help).
func (*OptProxyUint16) Aliases ¶ added in v6.1.0
func (o *OptProxyUint16) Aliases(aliases ...string) *OptProxyUint16
Aliases appends the aliases of the option and returns itself.
func (*OptProxyUint16) Default ¶ added in v6.1.0
func (o *OptProxyUint16) Default(_default interface{}) *OptProxyUint16
Default resets the default value of the option and returns itself.
func (*OptProxyUint16) Get ¶ added in v6.1.0
func (o *OptProxyUint16) Get() uint16
Get returns the value of the option.
func (*OptProxyUint16) IsCli ¶ added in v6.1.0
func (o *OptProxyUint16) IsCli(cli bool) *OptProxyUint16
IsCli resets the cli flag of the option and returns itself.
func (*OptProxyUint16) Name ¶ added in v6.1.0
func (o *OptProxyUint16) Name() string
Name returns the name of the option.
func (*OptProxyUint16) OnUpdate ¶ added in v6.1.0
func (o *OptProxyUint16) OnUpdate(f func(old, new interface{})) *OptProxyUint16
OnUpdate resets the update callback of the option and returns itself.
func (*OptProxyUint16) Opt ¶ added in v6.1.0
func (o *OptProxyUint16) Opt() Opt
Opt returns the registered and proxied option.
func (*OptProxyUint16) Parser ¶ added in v6.1.0
func (o *OptProxyUint16) Parser(parser Parser) *OptProxyUint16
Parser resets the parser of the option and returns itself.
func (*OptProxyUint16) Set ¶ added in v6.1.0
func (o *OptProxyUint16) Set(value interface{}) (err error)
Set sets the value of the option to value.
func (*OptProxyUint16) Short ¶ added in v6.1.0
func (o *OptProxyUint16) Short(short string) *OptProxyUint16
Short resets the short name of the option and returns itself.
func (*OptProxyUint16) Validators ¶ added in v6.1.0
func (o *OptProxyUint16) Validators(validators ...Validator) *OptProxyUint16
Validators appends the validators of the option and returns itself.
type OptProxyUint32 ¶
type OptProxyUint32 struct{ OptProxy }
OptProxyUint32 is a proxy for the uint32 option registered into Config, which can be used to modify the attributions of the option and update its value directly.
func NewUint32 ¶
func NewUint32(name string, _default uint32, help string) *OptProxyUint32
NewUint32 is equal to Conf.NewUint32(name, _default, help).
func (*OptProxyUint32) Aliases ¶
func (o *OptProxyUint32) Aliases(aliases ...string) *OptProxyUint32
Aliases appends the aliases of the option and returns itself.
func (*OptProxyUint32) Default ¶
func (o *OptProxyUint32) Default(_default interface{}) *OptProxyUint32
Default resets the default value of the option and returns itself.
func (*OptProxyUint32) Get ¶
func (o *OptProxyUint32) Get() uint32
Get returns the value of the option.
func (*OptProxyUint32) IsCli ¶
func (o *OptProxyUint32) IsCli(cli bool) *OptProxyUint32
IsCli resets the cli flag of the option and returns itself.
func (*OptProxyUint32) Name ¶
func (o *OptProxyUint32) Name() string
Name returns the name of the option.
func (*OptProxyUint32) OnUpdate ¶
func (o *OptProxyUint32) OnUpdate(f func(old, new interface{})) *OptProxyUint32
OnUpdate resets the update callback of the option and returns itself.
func (*OptProxyUint32) Opt ¶
func (o *OptProxyUint32) Opt() Opt
Opt returns the registered and proxied option.
func (*OptProxyUint32) Parser ¶
func (o *OptProxyUint32) Parser(parser Parser) *OptProxyUint32
Parser resets the parser of the option and returns itself.
func (*OptProxyUint32) Set ¶
func (o *OptProxyUint32) Set(value interface{}) (err error)
Set sets the value of the option to value.
func (*OptProxyUint32) Short ¶
func (o *OptProxyUint32) Short(short string) *OptProxyUint32
Short resets the short name of the option and returns itself.
func (*OptProxyUint32) Validators ¶
func (o *OptProxyUint32) Validators(validators ...Validator) *OptProxyUint32
Validators appends the validators of the option and returns itself.
type OptProxyUint64 ¶
type OptProxyUint64 struct{ OptProxy }
OptProxyUint64 is a proxy for the uint64 option registered into Config, which can be used to modify the attributions of the option and update its value directly.
func NewUint64 ¶
func NewUint64(name string, _default uint64, help string) *OptProxyUint64
NewUint64 is equal to Conf.NewUint64(name, _default, help).
func (*OptProxyUint64) Aliases ¶
func (o *OptProxyUint64) Aliases(aliases ...string) *OptProxyUint64
Aliases appends the aliases of the option and returns itself.
func (*OptProxyUint64) Default ¶
func (o *OptProxyUint64) Default(_default interface{}) *OptProxyUint64
Default resets the default value of the option and returns itself.
func (*OptProxyUint64) Get ¶
func (o *OptProxyUint64) Get() uint64
Get returns the value of the option.
func (*OptProxyUint64) IsCli ¶
func (o *OptProxyUint64) IsCli(cli bool) *OptProxyUint64
IsCli resets the cli flag of the option and returns itself.
func (*OptProxyUint64) Name ¶
func (o *OptProxyUint64) Name() string
Name returns the name of the option.
func (*OptProxyUint64) OnUpdate ¶
func (o *OptProxyUint64) OnUpdate(f func(old, new interface{})) *OptProxyUint64
OnUpdate resets the update callback of the option and returns itself.
func (*OptProxyUint64) Opt ¶
func (o *OptProxyUint64) Opt() Opt
Opt returns the registered and proxied option.
func (*OptProxyUint64) Parser ¶
func (o *OptProxyUint64) Parser(parser Parser) *OptProxyUint64
Parser resets the parser of the option and returns itself.
func (*OptProxyUint64) Set ¶
func (o *OptProxyUint64) Set(value interface{}) (err error)
Set sets the value of the option to value.
func (*OptProxyUint64) Short ¶
func (o *OptProxyUint64) Short(short string) *OptProxyUint64
Short resets the short name of the option and returns itself.
func (*OptProxyUint64) Validators ¶
func (o *OptProxyUint64) Validators(validators ...Validator) *OptProxyUint64
Validators appends the validators of the option and returns itself.
type OptProxyUintSlice ¶
type OptProxyUintSlice struct{ OptProxy }
OptProxyUintSlice is a proxy for the []uint option registered into Config, which can be used to modify the attributions of the option and update its value directly.
func NewUintSlice ¶
func NewUintSlice(name string, _default []uint, help string) *OptProxyUintSlice
NewUintSlice is equal to Conf.NewUintSlice(name, _default, help).
func (*OptProxyUintSlice) Aliases ¶
func (o *OptProxyUintSlice) Aliases(aliases ...string) *OptProxyUintSlice
Aliases appends the aliases of the option and returns itself.
func (*OptProxyUintSlice) Default ¶
func (o *OptProxyUintSlice) Default(_default interface{}) *OptProxyUintSlice
Default resets the default value of the option and returns itself.
func (*OptProxyUintSlice) Get ¶
func (o *OptProxyUintSlice) Get() []uint
Get returns the value of the option.
func (*OptProxyUintSlice) IsCli ¶
func (o *OptProxyUintSlice) IsCli(cli bool) *OptProxyUintSlice
IsCli resets the cli flag of the option and returns itself.
func (*OptProxyUintSlice) Name ¶
func (o *OptProxyUintSlice) Name() string
Name returns the name of the option.
func (*OptProxyUintSlice) OnUpdate ¶
func (o *OptProxyUintSlice) OnUpdate(f func(old, new interface{})) *OptProxyUintSlice
OnUpdate resets the update callback of the option and returns itself.
func (*OptProxyUintSlice) Opt ¶
func (o *OptProxyUintSlice) Opt() Opt
Opt returns the registered and proxied option.
func (*OptProxyUintSlice) Parser ¶
func (o *OptProxyUintSlice) Parser(parser Parser) *OptProxyUintSlice
Parser resets the parser of the option and returns itself.
func (*OptProxyUintSlice) Set ¶
func (o *OptProxyUintSlice) Set(value interface{}) (err error)
Set sets the value of the option to value.
func (*OptProxyUintSlice) Short ¶
func (o *OptProxyUintSlice) Short(short string) *OptProxyUintSlice
Short resets the short name of the option and returns itself.
func (*OptProxyUintSlice) Validators ¶
func (o *OptProxyUintSlice) Validators(validators ...Validator) *OptProxyUintSlice
Validators appends the validators of the option and returns itself.
type Parser ¶
type Parser func(input interface{}) (output interface{}, err error)
Parser is used to parse the option value intput.
type Source ¶
type Source interface { // String is the description of the source, such as "env", "file:/path/to". String() string // Read reads the source data once, which should not block. Read() (DataSet, error) // Watch watches the change of the source, then call the callback load. // // close is used to notice the underlying watcher to close and clean. Watch(close <-chan struct{}, load func(DataSet, error) (success bool)) }
Source represents a data source where the data is.
func NewEnvSource ¶
NewEnvSource returns a new Source based on the environment variables, which reads the configuration from the environment variables.
If giving the prefix, it only uses the environment variable name matching the given prefix, then removes the prefix and the rest is used as the option name.
Notice: It will convert all the underlines("_") to the dots(".").
func NewFileSource ¶
NewFileSource returns a new source that the data is read from the file named filename.
The file source can watch the change of the given file. And it will identify the format by the filename extension automatically. If no filename extension, it will use defaulFormat, which is "ini" by default.
func NewFlagSource ¶
NewFlagSource returns a new source based on flag.FlagSet, which is flag.CommandLine by default.
func NewURLSource ¶
NewURLSource returns a url source to read the configuration data from the url by the stdlib http.Get(url).
The header "Content-Type" indicates the data format, that's, it will split the value by "/" and use the last part, such as "application/json" represents the format "json". But you can set format to override it.
The url source can watch the configuration data from the url each interval period. If interval is equal to 0, it is defaulted to time.Minute.
type Validator ¶
type Validator func(value interface{}) error
Validator is used to validate whether the option value is valid.
func NewAddressOrIPSliceValidator ¶
func NewAddressOrIPSliceValidator() Validator
NewAddressOrIPSliceValidator returns a validator to validate whether the string element of the []string value is an address or ip.
func NewAddressOrIPValidator ¶
func NewAddressOrIPValidator() Validator
NewAddressOrIPValidator is equal to NewAddressValidator, but it maybe miss the port.
func NewAddressSliceValidator ¶
func NewAddressSliceValidator() Validator
NewAddressSliceValidator returns a validator to validate whether the string element of the []string value is a valid address.
func NewAddressValidator ¶
func NewAddressValidator() Validator
NewAddressValidator returns a validator to validate whether an address is like "host:port", "host%zone:port", "[host]:port" or "[host%zone]:port".
This validator uses net.SplitHostPort() to validate it.
func NewEmailSliceValidator ¶
func NewEmailSliceValidator() Validator
NewEmailSliceValidator returns a validator to validate whether the string element of the []string value is a valid email.
func NewEmailValidator ¶
func NewEmailValidator() Validator
NewEmailValidator returns a validator to validate whether an email is valid.
func NewEmptyStrValidator ¶
func NewEmptyStrValidator() Validator
NewEmptyStrValidator returns a validator to validate that the value must be an empty string.
func NewFloatRangeValidator ¶
NewFloatRangeValidator returns a validator to validate whether the float value is between the min and the max.
This validator can be used to validate the value of the type float32 and float64.
func NewIPSliceValidator ¶
func NewIPSliceValidator() Validator
NewIPSliceValidator returns a validator to validate whether the string element of the []string value is a valid IP.
func NewIPValidator ¶
func NewIPValidator() Validator
NewIPValidator returns a validator to validate whether an ip is valid.
func NewIntegerRangeValidator ¶
NewIntegerRangeValidator returns a validator to validate whether the integer value is between the min and the max.
This validator can be used to validate the value of the type int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64.
func NewMaybeAddressOrIPValidator ¶
func NewMaybeAddressOrIPValidator() Validator
NewMaybeAddressOrIPValidator returns a validator to validate the value may be empty or an address or an ip.
func NewMaybeAddressValidator ¶
func NewMaybeAddressValidator() Validator
NewMaybeAddressValidator returns a validator to validate the value may be empty or an address.
func NewMaybeEmailValidator ¶
func NewMaybeEmailValidator() Validator
NewMaybeEmailValidator returns a validator to validate the value may be empty or an email.
func NewMaybeIPValidator ¶
func NewMaybeIPValidator() Validator
NewMaybeIPValidator returns a validator to validate the value may be empty or a ip.
func NewMaybeURLValidator ¶
func NewMaybeURLValidator() Validator
NewMaybeURLValidator returns a validator to validate the value may be empty or a URL.
func NewPortValidator ¶
func NewPortValidator() Validator
NewPortValidator returns a validator to validate whether a port is between 0 and 65535.
func NewRegexpValidator ¶
NewRegexpValidator returns a validator to validate whether the value match the regular expression.
This validator uses regexp.MatchString(pattern, s) to validate it.
func NewStrArrayValidator ¶
NewStrArrayValidator returns a validator to validate that the value is in the array.
func NewStrLenValidator ¶
NewStrLenValidator returns a validator to validate that the length of the string must be between min and max.
func NewStrNotEmptyValidator ¶
func NewStrNotEmptyValidator() Validator
NewStrNotEmptyValidator returns a validator to validate that the value must not be an empty string.
func NewStrSliceValidator ¶
NewStrSliceValidator returns a validator to validate whether the string element of the []string value satisfies all the given validators.
func NewURLSliceValidator ¶
func NewURLSliceValidator() Validator
NewURLSliceValidator returns a validator to validate whether the string element of the []string value is a valid URL.
func NewURLValidator ¶
func NewURLValidator() Validator
NewURLValidator returns a validator to validate whether a url is valid.