Documentation
¶
Index ¶
- Constants
- func AtomicConfigSet(update interface{})
- func ConfigOptionDeclareWithDefault() interface{}
- func InstallCallbackOnAtomicConfigSet(callback func(cc ConfigInterface) bool)
- func InstallConfigWatchDog(dog func(cc *Config))
- func ParseDir(dir string)
- type BufWrite
- type Config
- func (cc *Config) ApplyOption(opts ...ConfigOption) []ConfigOption
- func (cc *Config) AtomicSetFunc() func(interface{})
- func (cc *Config) GetDebug() bool
- func (cc *Config) GetEmptyCompositeNil() bool
- func (cc *Config) GetNewFunc() string
- func (cc *Config) GetNewFuncReturn() string
- func (cc *Config) GetOptionPrefix() string
- func (cc *Config) GetOptionReturnPrevious() bool
- func (cc *Config) GetOptionWithStructName() bool
- func (cc *Config) GetSliceOnlyAppend() bool
- func (cc *Config) GetUsageTagName() string
- func (cc *Config) GetVerbose() booldeprecated
- func (cc *Config) GetXConf() bool
- func (cc *Config) GetXConfTrimPrefix() string
- type ConfigInterface
- type ConfigOption
- func WithDebug(v bool) ConfigOption
- func WithEmptyCompositeNil(v bool) ConfigOption
- func WithNewFunc(v string) ConfigOption
- func WithNewFuncReturn(v string) ConfigOption
- func WithOptionPrefix(v string) ConfigOption
- func WithOptionReturnPrevious(v bool) ConfigOption
- func WithOptionWithStructName(v bool) ConfigOption
- func WithSliceOnlyAppend(v bool) ConfigOption
- func WithUsageTagName(v string) ConfigOption
- func WithVerbose(v bool) ConfigOptiondeprecated
- func WithXConf(v bool) ConfigOption
- func WithXConfTrimPrefix(v string) ConfigOption
- type ConfigVisitor
- type FieldType
Constants ¶
const ( AnnotationKeyComment = "comment" AnnotationKeyPrivate = "private" AnnotationKeyArg = "arg" AnnotationKeyXConfTag = "xconf" AnnotationKeyGetter = "getter" AnnotationKeyOption = "option" AnnotationKeyAppend = "append" AnnotationKeyVisit = "visit" AnnotationKeyInline = "inline" AnnotationKeyDeprecated = "deprecated" AnnotationKeyTag = "tag_" AnnotationKeySliceOnlyAppend = "slice_only_append" )
const NewFuncReturnInterface = "interface"
const NewFuncReturnPointer = "pointer"
const NewFuncReturnVisitor = "visitor"
const (
OptionGen = "optiongen"
)
Variables ¶
This section is empty.
Functions ¶
func AtomicConfigSet ¶
func AtomicConfigSet(update interface{})
AtomicConfigSet atomic setter for *Config
func ConfigOptionDeclareWithDefault ¶
func ConfigOptionDeclareWithDefault() interface{}
func InstallCallbackOnAtomicConfigSet ¶ added in v1.0.1
func InstallCallbackOnAtomicConfigSet(callback func(cc ConfigInterface) bool)
InstallCallbackOnAtomicConfigSet install callback
func InstallConfigWatchDog ¶
func InstallConfigWatchDog(dog func(cc *Config))
InstallConfigWatchDog the installed func will called when NewTestConfig called
Types ¶
type Config ¶
type Config struct { OptionPrefix string `xconf:"option_prefix" usage:"option func name prefix, like: With, WithRedis"` // annotation@OptionPrefix(comment="option func name prefix, like: With, WithRedis") OptionWithStructName bool `xconf:"option_with_struct_name" usage:"should the option func with struct name?"` // annotation@OptionWithStructName(comment="should the option func with struct name?") OptionReturnPrevious bool `xconf:"option_return_previous" usage:"should option func return the previous ones?"` // annotation@OptionReturnPrevious(comment="should option func return the previous ones?") NewFunc string `xconf:"new_func" usage:"new function name"` // annotation@NewFunc(comment="new function name") NewFuncReturn string `xconf:"new_func_return" usage:"valid data: pointer,interface,visitor"` // annotation@NewFuncReturn(comment="valid data: pointer,interface,visitor") Verbose bool `xconf:"v,deprecated" usage:"Deprecated: use --debug instead"` // annotation@Verbose(xconf="v",deprecated="use --debug instead") UsageTagName string `xconf:"usage_tag_name" usage:"usage tag name,if not empty,will gen usage support for xconf/xflag"` // annotation@UsageTagName(comment="usage tag name,if not empty,will gen usage support for xconf/xflag") EmptyCompositeNil bool `xconf:"empty_composite_nil" usage:"should empty slice or map to be nil? otherwise will be make(XXXX,0)"` // annotation@EmptyCompositeNil(comment="should empty slice or map to be nil? otherwise will be make(XXXX,0)") Debug bool `xconf:"debug" usage:"debug will print more detail info"` // annotation@Debug(comment="debug will print more detail info") XConf bool `xconf:"xconf" usage:"should gen xconf tag support?"` // annotation@XConf(xconf="xconf",comment="should gen xconf tag support?") XConfTrimPrefix string `xconf:"x_conf_trim_prefix" usage:"if enable xconf tag, the tag value will trim prefix [XConfTrimPrefix]"` // annotation@XConfTrimPrefix(comment="if enable xconf tag, the tag value will trim prefix [XConfTrimPrefix]") SliceOnlyAppend bool `xconf:"slice_only_append" usage:"slice only has append func, has not option func, like: With, WithRedis"` // annotation@SliceOnlyAppend(comment="slice only has append func, has not option func, like: With, WithRedis ") }
Config should use NewTestConfig to initialize it
func (*Config) ApplyOption ¶
func (cc *Config) ApplyOption(opts ...ConfigOption) []ConfigOption
ApplyOption apply multiple new option and return the old ones sample: old := cc.ApplyOption(WithTimeout(time.Second)) defer cc.ApplyOption(old...)
func (*Config) AtomicSetFunc ¶
func (cc *Config) AtomicSetFunc() func(interface{})
AtomicSetFunc used for XConf
func (*Config) GetEmptyCompositeNil ¶
func (*Config) GetNewFunc ¶
func (*Config) GetNewFuncReturn ¶ added in v1.0.1
func (*Config) GetOptionReturnPrevious ¶
func (*Config) GetOptionWithStructName ¶
func (*Config) GetSliceOnlyAppend ¶ added in v1.0.9
func (*Config) GetUsageTagName ¶
func (*Config) GetVerbose
deprecated
func (*Config) GetXConfTrimPrefix ¶
type ConfigInterface ¶
type ConfigInterface interface { ConfigVisitor ApplyOption(...ConfigOption) []ConfigOption }
ConfigInterface visitor + ApplyOption interface for Config
type ConfigOption ¶
type ConfigOption func(cc *Config) ConfigOption
ConfigOption option func
func WithEmptyCompositeNil ¶
func WithEmptyCompositeNil(v bool) ConfigOption
WithEmptyCompositeNil should empty slice or map to be nil? otherwise will be make(XXXX,0)
func WithNewFuncReturn ¶ added in v1.0.1
func WithNewFuncReturn(v string) ConfigOption
WithNewFuncReturn valid data: pointer,interface,visitor
func WithOptionPrefix ¶
func WithOptionPrefix(v string) ConfigOption
WithOptionPrefix option func name prefix, like: With, WithRedis
func WithOptionReturnPrevious ¶
func WithOptionReturnPrevious(v bool) ConfigOption
WithOptionReturnPrevious should option func return the previous ones?
func WithOptionWithStructName ¶
func WithOptionWithStructName(v bool) ConfigOption
WithOptionWithStructName should the option func with struct name?
func WithSliceOnlyAppend ¶ added in v1.0.9
func WithSliceOnlyAppend(v bool) ConfigOption
WithSliceOnlyAppend slice only has append func, has not option func, like: With, WithRedis
func WithUsageTagName ¶
func WithUsageTagName(v string) ConfigOption
WithUsageTagName usage tag name,if not empty,will gen usage support for xconf/xflag
func WithVerbose
deprecated
func WithVerbose(v bool) ConfigOption
WithVerbose option func for filed Verbose
Deprecated: use --debug instead
func WithXConfTrimPrefix ¶
func WithXConfTrimPrefix(v string) ConfigOption
WithXConfTrimPrefix if enable xconf tag, the tag value will trim prefix [XConfTrimPrefix]
type ConfigVisitor ¶
type ConfigVisitor interface { GetOptionPrefix() string GetOptionWithStructName() bool GetOptionReturnPrevious() bool GetNewFunc() string GetNewFuncReturn() string // GetVerbose visitor func for filed Verbose // // Deprecated: use --debug instead GetVerbose() bool GetUsageTagName() string GetEmptyCompositeNil() bool GetDebug() bool GetXConf() bool GetXConfTrimPrefix() string GetSliceOnlyAppend() bool }
ConfigVisitor visitor interface for Config