Documentation
¶
Index ¶
- Constants
- Variables
- func AtomicOptionsSet(update interface{})
- func DumpInfo()
- func FieldMap(valPtr interface{}, x *XConf) map[string]StructFieldPathInfo
- func FieldPathList(valPtr interface{}, x *XConf) (ret []string)
- func FlagTypeStr(x *XConf, name string) (tag string)
- func Hash() (s string)
- func HashStructure(v interface{}) (s string)
- func InstallCallbackOnAtomicOptionsSet(callback func(cc OptionsInterface) bool)
- func InstallOptionsWatchDog(dog func(cc *Options))
- func IsErrHelp(err error) bool
- func Latest() (interface{}, error)
- func LookupEnvCaseInsensitive(key string) (string, bool)
- func Merge(opts ...Option) error
- func MustParse(valPtr interface{}, opts ...Option)
- func MustSaveToBytes(ct ConfigType) []byte
- func MustSaveToFile(f string)
- func MustSaveToWriter(ct ConfigType, writer io.Writer)
- func MustSaveVarToFile(v interface{}, f string)
- func MustSaveVarToWriter(v interface{}, ct ConfigType, w io.Writer)
- func NewRemoteReader(url string, timeout time.Duration, headerkv ...string) io.Reader
- func NotifyUpdate() <-chan interface{}
- func OptionsOptionDeclareWithDefault() interface{}
- func Parse(valPtr interface{}, opts ...Option) error
- func ParseDefault(valPtr interface{}, opts ...Option) (err error)
- func ParseEnvValue(val string) (newVal string, err error)
- func RegisterCodec(ct ConfigType, d DecodeFunc, e EncodeFunc)
- func SaveToFile(fileName string) error
- func SaveToWriter(ct ConfigType, writer io.Writer) error
- func SaveVarToFile(valPtr interface{}, fileName string) error
- func SaveVarToWriter(valPtr interface{}, ct ConfigType, writer io.Writer) error
- func SaveVarToWriterAsYAML(valPtr interface{}, writer io.Writer) error
- func StringAlias(alias map[string]string, aliasFunc map[string]func(string) string) mapstructure.DecodeHookFunc
- func UpdateWithEnviron(environ ...string) (err error)
- func UpdateWithFieldPathValues(kv ...string) (err error)
- func UpdateWithFiles(files ...string) (err error)
- func UpdateWithFlagArgs(flagArgs ...string) (err error)
- func UpdateWithReader(readers ...io.Reader) (err error)
- func Usage()
- func WatchFieldPath(fieldPath string, changed OnFieldUpdated)
- func WatchUpdate(confPath string, loader kv.Loader)
- type AtomicSetterProvider
- type ConfigType
- type DecodeFunc
- type DecoderConfigOption
- type EncodeFunc
- type ErrorHandling
- type FieldTagConvertor
- type GetOptionUsage
- type LogFunc
- type OnFieldUpdated
- type Option
- func WithAppLabelList(v ...string) Option
- func WithDebug(v bool) Option
- func WithDecoderConfigOption(v ...DecoderConfigOption) Option
- func WithEnvBindShouldErrorWhenFailed(v bool) Option
- func WithEnviron(v ...string) Option
- func WithEnvironPrefix(v string) Option
- func WithErrorHandling(v ErrorHandling) Option
- func WithErrorUnused(v bool) Option
- func WithFieldPathRemoved(v ...string) Option
- func WithFieldTagConvertor(v FieldTagConvertor) Option
- func WithFiles(v ...string) Option
- func WithFlagArgs(v ...string) Option
- func WithFlagCreateIgnoreFiledPath(v ...string) Option
- func WithFlagSet(v *flag.FlagSet) Option
- func WithLogDebug(v LogFunc) Option
- func WithLogWarning(v LogFunc) Option
- func WithMapMerge(v bool) Option
- func WithOptionUsage(v string) Option
- func WithOptionUsagePoweredBy(v string) Option
- func WithParseDefault(v bool) Option
- func WithParseMetaKeyFlagFiles(v bool) Option
- func WithReaders(v ...io.Reader) Option
- func WithReplaceFlagSetUsage(v bool) Option
- func WithStringAlias(v map[string]string) Option
- func WithStringAliasFunc(v map[string]func(s string) string) Option
- func WithTagName(v string) Option
- func WithTagNameForDefaultValue(v string) Option
- type Options
- func (cc *Options) ApplyOption(opts ...Option) []Option
- func (cc *Options) AtomicSetFunc() func(interface{})
- func (cc *Options) GetAppLabelList() []string
- func (cc *Options) GetDebug() bool
- func (cc *Options) GetDecoderConfigOption() []DecoderConfigOption
- func (cc *Options) GetEnvBindShouldErrorWhenFailed() bool
- func (cc *Options) GetEnviron() []string
- func (cc *Options) GetEnvironPrefix() string
- func (cc *Options) GetErrorHandling() ErrorHandling
- func (cc *Options) GetErrorUnused() bool
- func (cc *Options) GetFieldPathRemoved() []string
- func (cc *Options) GetFieldTagConvertor() FieldTagConvertor
- func (cc *Options) GetFiles() []string
- func (cc *Options) GetFlagArgs() []string
- func (cc *Options) GetFlagCreateIgnoreFiledPath() []string
- func (cc *Options) GetFlagSet() *flag.FlagSet
- func (cc *Options) GetLogDebug() LogFunc
- func (cc *Options) GetLogWarning() LogFunc
- func (cc *Options) GetMapMerge() bool
- func (cc *Options) GetOptionUsage() string
- func (cc *Options) GetOptionUsagePoweredBy() string
- func (cc *Options) GetParseDefault() bool
- func (cc *Options) GetParseMetaKeyFlagFiles() bool
- func (cc *Options) GetReaders() []io.Reader
- func (cc *Options) GetReplaceFlagSetUsage() bool
- func (cc *Options) GetStringAlias() map[string]string
- func (cc *Options) GetStringAliasFunc() map[string]func(s string) string
- func (cc *Options) GetTagName() string
- func (cc *Options) GetTagNameForDefaultValue() string
- type OptionsInterface
- type OptionsVisitor
- type Struct
- type StructFieldPathInfo
- type XConf
- func (x *XConf) Copy() *XConf
- func (x *XConf) DumpInfo()
- func (x *XConf) Hash() (s string)
- func (x *XConf) HashStructure(v interface{}) (s string)
- func (x *XConf) Latest() (interface{}, error)
- func (x *XConf) Merge(opts ...Option) error
- func (x *XConf) MustParse(valPtr interface{}, opts ...Option)
- func (x *XConf) MustSaveToBytes(ct ConfigType) []byte
- func (x *XConf) MustSaveToFile(fileName string)
- func (x *XConf) MustSaveToWriter(ct ConfigType, writer io.Writer)
- func (x *XConf) MustSaveVarToFile(valPtr interface{}, fileName string)
- func (x *XConf) MustSaveVarToWriter(valPtr interface{}, ct ConfigType, writer io.Writer)
- func (x *XConf) NotifyUpdate() <-chan interface{}
- func (x *XConf) Parse(valPtr interface{}, opts ...Option) error
- func (x *XConf) SaveToFile(fileName string) error
- func (x *XConf) SaveToWriter(ct ConfigType, writer io.Writer) error
- func (x *XConf) SaveVarToFile(valPtr interface{}, fileName string) error
- func (x *XConf) SaveVarToWriter(valPtr interface{}, ct ConfigType, writer io.Writer) error
- func (x *XConf) SaveVarToWriterAsYAML(valPtr interface{}, writer io.Writer) error
- func (x *XConf) StructMapStructure(s interface{}) map[string]interface{}
- func (x *XConf) UpdateWithEnviron(environ ...string) (err error)
- func (x *XConf) UpdateWithFieldPathValues(kv ...string) (err error)
- func (x *XConf) UpdateWithFiles(files ...string) (err error)
- func (x *XConf) UpdateWithFlagArgs(flagArgs ...string) (err error)
- func (x *XConf) UpdateWithReader(readers ...io.Reader) (err error)
- func (x *XConf) Usage()
- func (x *XConf) UsageToWriter(w io.Writer, args ...string)
- func (x *XConf) WatchFieldPath(fieldPath string, changed OnFieldUpdated)
- func (x *XConf) WatchUpdate(confPath string, loader kv.Loader)
- func (x *XConf) ZeroStructKeysTagList(s interface{}) map[string]StructFieldPathInfo
- type XConfOptions
Constants ¶
const ( // MetaKeyFlagFiles 元数据,flag中使用,用于通过flag指定需加载的配置文件列表 // 多个文件以,分割,如server --xconf_flag_files=base.yaml,testflight.yaml MetaKeyFlagFiles = "xconf_flag_files" // MetaKeyInheritFiles 元数据,配置文件内使用,用于指定继承的文件 // 如toml中配置:xconf_inherit_files=[etcd.yaml,production.yaml],则当前配置会继承etcd.yaml,production.yaml文件 MetaKeyInheritFiles = "xconf_inherit_files" // MetaKeyGrayLabel 元数据,灰度发布支持,发布配置的的时候指定配置生次奥的label // xconf运行时可以通过WithAppLabelList指定label,当MetaKeyGrayLabel不为空且至少含有一个AppLabelList中的label时配置会应用到当前实例 MetaKeyGrayLabel = "xconf_gray_rule_label" // MetaKeyLatestHash 元数据,预留用于配置版本的比对、校验 MetaKeyLatestHash = "xconf_latest_hash" // MetaKeyInheritFilesDeprecatedFromGoconf 同MetaKeyInheritFiles,兼容goconf MetaKeyInheritFilesDeprecatedFromGoconf = "inherit_files" )
const ( // HashPrefix hash字段前缀 HashPrefix = "xconf@" // DefaultInvalidHashString 默认hash值 DefaultInvalidHashString = HashPrefix + "hash_invalid" )
Variables ¶
var DefaultKeyDelim = "."
DefaultKeyDelim 默认的FilePath分割符
var DefaultTagName = "xconf"
DefaultTagName 默认读取的tag名
var DefaultValueTagName = "default"
DefaultValueTagName default value 默认读取的tag名
var ErrHelp = flag.ErrHelp
ErrHelp is the error returned if the -help or -h flag is invoked but no such flag is defined.
var LookupEnv = LookupEnvCaseInsensitive
LookupEnv Env value provider func. 默认提供不缺分大小写的env绑定模式
Functions ¶
func AtomicOptionsSet ¶
func AtomicOptionsSet(update interface{})
AtomicOptionsSet atomic setter for *Options
func FieldMap ¶ added in v0.2.6
func FieldMap(valPtr interface{}, x *XConf) map[string]StructFieldPathInfo
FieldMap 获取对象的Field对象Map
func FieldPathList ¶ added in v0.2.6
FieldPathList 获取对象的FieldPath列表
func FlagTypeStr ¶ added in v0.2.7
FlagTypeStr 获取子弹标记,Y代表xconf解析管理的配置,M标识xconf内置配置,D标识Deprecated,-表示为非xconf管理的配置
func InstallCallbackOnAtomicOptionsSet ¶
func InstallCallbackOnAtomicOptionsSet(callback func(cc OptionsInterface) bool)
InstallCallbackOnAtomicOptionsSet install callback
func InstallOptionsWatchDog ¶
func InstallOptionsWatchDog(dog func(cc *Options))
InstallOptionsWatchDog the installed func will called when NewOptions called
func Latest ¶
func Latest() (interface{}, error)
Latest 将xconf内缓存的配置数据绑定到Parse时传入类型,逻辑层需要将返回的interface{}转换到相应的配置指针
func LookupEnvCaseInsensitive ¶ added in v0.3.26
LookupEnvCaseInsensitive 查找环境变量,大小写不敏感
func MustParse ¶ added in v0.3.4
func MustParse(valPtr interface{}, opts ...Option)
MustParse 解析配置到传入的参数中,如发生错误则直接panic
func MustSaveToBytes ¶
func MustSaveToBytes(ct ConfigType) []byte
MustSaveToBytes 将内置解析的数据以字节流返回,需指定ConfigType
func MustSaveToFile ¶
func MustSaveToFile(f string)
MustSaveToFile 将内置解析的数据dump到文件,根据文件后缀选择codec,如发生错误会panic
func MustSaveToWriter ¶
func MustSaveToWriter(ct ConfigType, writer io.Writer)
MustSaveToWriter 将内置解析的数据dump到writer,需指定ConfigType,如发生错误会panic
func MustSaveVarToFile ¶
func MustSaveVarToFile(v interface{}, f string)
MustSaveVarToFile 将外部传入的valPtr,写入到fileName中,根据文件后缀选择codec
func MustSaveVarToWriter ¶
func MustSaveVarToWriter(v interface{}, ct ConfigType, w io.Writer)
MustSaveVarToWriter 将外部传入的valPtr,写入到writer中,类型为ct
func NewRemoteReader ¶
NewRemoteReader 返回一个远程Reader,指定url及超时时间
func OptionsOptionDeclareWithDefault ¶
func OptionsOptionDeclareWithDefault() interface{}
OptionsOptionDeclareWithDefault go-lint
func ParseDefault ¶
ParseDefault 根据opts指定的TagNameDefaultValue解析字段默认值并绑定到valPtr
func ParseEnvValue ¶
ParseEnvValue parse ENV var value from input string, support default value.
func RegisterCodec ¶
func RegisterCodec(ct ConfigType, d DecodeFunc, e EncodeFunc)
RegisterCodec 注册自定义的Codec
func SaveToWriter ¶
func SaveToWriter(ct ConfigType, writer io.Writer) error
SaveToWriter 将内置解析的数据dump到writer,类型为ct
func SaveVarToFile ¶
SaveVarToFile 将外部传入的valPtr,写入到fileName中,根据文件后缀选择codec
func SaveVarToWriter ¶
func SaveVarToWriter(valPtr interface{}, ct ConfigType, writer io.Writer) error
SaveVarToWriter 将外部传入的valPtr,写入到writer中,类型为ct
func SaveVarToWriterAsYAML ¶ added in v0.3.5
SaveVarToWriterAsYAML 将内置解析的数据解析到yaml,带comment
func StringAlias ¶ added in v0.2.6
func StringAlias(alias map[string]string, aliasFunc map[string]func(string) string) mapstructure.DecodeHookFunc
func UpdateWithEnviron ¶
UpdateWithEnviron 提供环境变量合法配置更新数据,通过NotifyUpdate异步通知更新或通过Latest同步获取
func UpdateWithFieldPathValues ¶
UpdateWithFieldPathValues 根据字段FieldPath更新数据, 支持的字段类型依赖于xflag,通过NotifyUpdate异步通知更新或通过Latest同步获取
func UpdateWithFiles ¶
UpdateWithFiles 通过文件更新配置,通过NotifyUpdate异步通知更新或通过Latest同步获取
func UpdateWithFlagArgs ¶
UpdateWithFlagArgs 提供FlagSet合法参数更新数据,通过NotifyUpdate异步通知更新或通过Latest同步获取
func UpdateWithReader ¶
UpdateWithReader 通过reader更新配置,通过NotifyUpdate异步通知更新或通过Latest同步获取
func WatchFieldPath ¶
func WatchFieldPath(fieldPath string, changed OnFieldUpdated)
WatchFieldPath 关注特定的字段变化
func WatchUpdate ¶
WatchUpdate confPath不会自动绑定env value,如果需要watch的路径与环境变量相关,先通过ParseEnvValue自行解析替换处理错误
Types ¶
type AtomicSetterProvider ¶ added in v0.2.6
type AtomicSetterProvider interface {
AtomicSetFunc() func(interface{})
}
AtomicSetterProvider Atomic设置配置的方法提供接口,配置层提供改方法供XConf自动设定最新配置
type ConfigType ¶
type ConfigType string
ConfigType 编解码类型
const ConfigTypeJSON ConfigType = ".json"
ConfigTypeJSON json编解码类型
const ConfigTypeTOML ConfigType = ".toml"
ConfigTypeTOML toml编解码类型
const ConfigTypeYAML ConfigType = ".yaml"
ConfigTypeYAML yaml编解码类型
type DecodeFunc ¶
DecodeFunc 解码方法签名
type DecoderConfigOption ¶
type DecoderConfigOption = func(*mapstructure.DecoderConfig)
DecoderConfigOption A DecoderConfigOption can be passed to Unmarshal to configure mapstructure.DecoderConfig options
type EncodeFunc ¶
EncodeFunc 编码方法签名
type ErrorHandling ¶
type ErrorHandling int
ErrorHandling 错误处理类型
const ( // ContinueOnError 发生错误继续运行,Parse会返回错误 ContinueOnError ErrorHandling = iota // ExitOnError 发生错误后退出 ExitOnError // PanicOnError 发生错误后主动panic PanicOnError )
type FieldTagConvertor ¶
FieldTagConvertor filed名称转换方法
type GetOptionUsage ¶ added in v0.2.6
type GetOptionUsage interface {
GetOptionUsage() string
}
GetOptionUsage 配置层提供改方法供XConf获取配置说明打印Usage
type OnFieldUpdated ¶
type OnFieldUpdated func(fieldPath string, from, to interface{})
OnFieldUpdated 字段发生变化方法签名
type Option ¶
Option option func
func WithAppLabelList ¶
WithAppLabelList 应用层Label,用于灰度发布场景
func WithDecoderConfigOption ¶
func WithDecoderConfigOption(v ...DecoderConfigOption) Option
WithDecoderConfigOption xconf内部依赖mapstructure,改方法用户用户层自定义mapstructure解析参数,参考:https://github.com/sandwich-go/mapstructure
func WithEnvBindShouldErrorWhenFailed ¶ added in v0.2.5
WithEnvBindShouldErrorWhenFailed EnvBind时如果Env中不存在指定的key而且没有指定默认值时是否返回错误
func WithEnviron ¶
WithEnviron Parse解析的环境变量,默认os.Environ(),内部转换为FlagSet处理,可通过--help获取当前支持的FlagSet与Env参数定义
func WithEnvironPrefix ¶ added in v0.2.8
WithEnvironPrefix 绑定ENV前缀,防止ENV名称覆盖污染
func WithErrorUnused ¶ added in v0.3.15
WithErrorUnused 当配置中出现未用到的字段时是否认为是错误
func WithFieldPathRemoved ¶ added in v0.2.5
WithFieldPathRemoved 弃用的配置,目标结构中已经删除,但配置文件中可能存在,解析时不会认为是错误,会将该配置丢弃,并打印WARNING日志
func WithFieldTagConvertor ¶
func WithFieldTagConvertor(v FieldTagConvertor) Option
WithFieldTagConvertor 字段名转换到FiledPath时优先使用TagName指定的名称,否则使用该函数转换
func WithFlagArgs ¶
WithFlagArgs FlagSet解析使用的Args列表,默认为os.Args[1:],如指定为空则不会触发FlagSet的定义和解析逻辑
func WithFlagCreateIgnoreFiledPath ¶ added in v0.2.5
WithFlagCreateIgnoreFiledPath 不创建到FlagSet中的字段FieldPath
func WithFlagSet ¶
WithFlagSet Parse使用的FlagSet,xconf会自动在flag中创建字段定义,如指定为空则不会创建
func WithOptionUsage ¶ added in v0.2.5
WithOptionUsage option func for filed OptionUsage
func WithOptionUsagePoweredBy ¶ added in v0.3.11
WithOptionUsagePoweredBy --help中显示Power by
func WithParseDefault ¶
WithParseDefault 是否解析struct标签中的default数据,解析规则参考xflag支持
func WithParseMetaKeyFlagFiles ¶ added in v0.2.6
WithParseMetaKeyFlagFiles 是否解析flag中的MetaKeyFlagFiles指定的文件
func WithReplaceFlagSetUsage ¶ added in v0.2.6
WithReplaceFlagSetUsage 是否替换FlagSet的Usage,使用xconf内置版本
func WithStringAlias ¶ added in v0.2.6
WithStringAlias 值别名
func WithStringAliasFunc ¶ added in v0.2.6
WithStringAliasFunc 值别名计算逻辑
func WithTagNameForDefaultValue ¶ added in v0.2.5
WithTagNameForDefaultValue 默认值TAG名称,默认default
type Options ¶
type Options struct { OptionUsage string `xconf:"option_usage"` // annotation@NewFunc(comment="Parse时会由指定的File中加载配置") Files []string `xconf:"files"` // annotation@Readers(comment="Parse时会由指定的Reader中加载配置") Readers []io.Reader `xconf:"readers" usage:"Parse时会由指定的Reader中加载配置"` // annotation@FlagSet(comment="Parse使用的FlagSet,xconf会自动在flag中创建字段定义,如指定为空则不会创建") FlagSet *flag.FlagSet `xconf:"flag_set" usage:"Parse使用的FlagSet,xconf会自动在flag中创建字段定义,如指定为空则不会创建"` // annotation@FlagArgs(comment="FlagSet解析使用的Args列表,默认为os.Args[1:],如指定为空则不会触发FlagSet的定义和解析逻辑") FlagArgs []string `` /* 145-byte string literal not displayed */ // annotation@Environ(comment="Parse解析的环境变量,默认os.Environ(),内部转换为FlagSet处理,可通过--help获取当前支持的FlagSet与Env参数定义") Environ []string `` /* 164-byte string literal not displayed */ // annotation@ErrorHandling(comment="错误处理模式") ErrorHandling ErrorHandling `xconf:"error_handling" usage:"错误处理模式"` // annotation@TagName(comment="xconf使用的字段TAG名称,默认:xconf") TagName string `xconf:"tag_name" usage:"xconf使用的字段TAG名称,默认:xconf"` // annotation@DecoderConfigOption(comment="xconf内部依赖mapstructure,改方法用户用户层自定义mapstructure解析参数,参考:https://github.com/sandwich-go/mapstructure") DecoderConfigOption []DecoderConfigOption `` /* 180-byte string literal not displayed */ // annotation@MapMerge(comment="map是否开启merge模式,详情见文档") MapMerge bool `xconf:"map_merge" usage:"map是否开启merge模式,详情见文档"` // annotation@FieldTagConvertor(comment="字段名转换到FiledPath时优先使用TagName指定的名称,否则使用该函数转换") FieldTagConvertor FieldTagConvertor `` /* 130-byte string literal not displayed */ // annotation@FieldPathRemoved(comment="弃用的配置,目标结构中已经删除,但配置文件中可能存在,解析时不会认为是错误,会将该配置丢弃,并打印WARNING日志") FieldPathRemoved []string `` /* 195-byte string literal not displayed */ // annotation@Debug(comment="debug模式下输出调试信息") Debug bool `xconf:"debug" usage:"debug模式下输出调试信息"` // annotation@LogDebug(comment="DEBUG日志") LogDebug LogFunc `xconf:"log_debug" usage:"DEBUG日志"` // annotation@LogWarning(comment="WARNING日志") LogWarning LogFunc `xconf:"log_warning" usage:"WARNING日志"` // annotation@AppLabelList(comment="应用层Label,用于灰度发布场景") AppLabelList []string `xconf:"app_label_list" usage:"应用层Label,用于灰度发布场景"` // annotation@EnvBindShouldErrorWhenFailed(comment="EnvBind时如果Env中不存在指定的key而且没有指定默认值时是否返回错误") EnvBindShouldErrorWhenFailed bool `` /* 141-byte string literal not displayed */ // annotation@FlagCreateIgnoreFiledPath(comment="不创建到FlagSet中的字段FieldPath") // todo: 可以通过tag中指定flagoff规避这个字段的支持 FlagCreateIgnoreFiledPath []string `xconf:"flag_create_ignore_filed_path" usage:"不创建到FlagSet中的字段FieldPath"` // annotation@ParseDefault(comment="是否解析struct标签中的default数据,解析规则参考xflag支持") ParseDefault bool `xconf:"parse_default" usage:"是否解析struct标签中的default数据,解析规则参考xflag支持"` // annotation@TagNameForDefaultValue(comment="默认值TAG名称,默认default") TagNameForDefaultValue string `xconf:"tag_name_for_default_value" usage:"默认值TAG名称,默认default"` // annotation@ReplaceFlagSetUsage(comment="是否替换FlagSet的Usage,使用xconf内置版本") ReplaceFlagSetUsage bool `xconf:"replace_flag_set_usage" usage:"是否替换FlagSet的Usage,使用xconf内置版本"` // annotation@ParseMetaKeyFlagFiles(comment="是否解析flag中的MetaKeyFlagFiles指定的文件") // 当一个app中有多个根配置,只能有一个根配置解析flag中的配置文件 ParseMetaKeyFlagFiles bool `xconf:"parse_meta_key_flag_files" usage:"是否解析flag中的MetaKeyFlagFiles指定的文件"` // annotation@EnvironPrefix(comment="绑定ENV前缀,防止ENV名称覆盖污染") EnvironPrefix string `xconf:"environ_prefix" usage:"绑定ENV前缀,防止ENV名称覆盖污染"` // annotation@OptionUsagePoweredBy(comment="--help中显示Power by") OptionUsagePoweredBy string `xconf:"option_usage_powered_by" usage:"--help中显示Power by"` // annotation@ErrorUnused(comment="当配置中出现未用到的字段时是否认为是错误") ErrorUnused bool `xconf:"error_unused" usage:"当配置中出现未用到的字段时是否认为是错误"` // annotation@StringAlias(comment="值别名") StringAlias map[string]string `xconf:"string_alias" usage:"值别名"` // annotation@StringAliasFunc(comment="值别名计算逻辑") StringAliasFunc map[string]func(s string) string `xconf:"string_alias_func" usage:"值别名计算逻辑"` }
Options should use NewOptions to initialize it
func (*Options) ApplyOption ¶
ApplyOption apply multiple new option and return the old ones sample: old := cc.ApplyOption(WithTimeout(time.Second)) defer cc.ApplyOption(old...)
func (*Options) AtomicSetFunc ¶
func (cc *Options) AtomicSetFunc() func(interface{})
AtomicSetFunc used for XConf
func (*Options) GetAppLabelList ¶
func (*Options) GetDecoderConfigOption ¶
func (cc *Options) GetDecoderConfigOption() []DecoderConfigOption
func (*Options) GetEnvBindShouldErrorWhenFailed ¶ added in v0.2.5
func (*Options) GetEnviron ¶
func (*Options) GetEnvironPrefix ¶ added in v0.2.8
func (*Options) GetErrorHandling ¶
func (cc *Options) GetErrorHandling() ErrorHandling
func (*Options) GetErrorUnused ¶ added in v0.3.15
func (*Options) GetFieldPathRemoved ¶ added in v0.2.5
func (*Options) GetFieldTagConvertor ¶
func (cc *Options) GetFieldTagConvertor() FieldTagConvertor
func (*Options) GetFlagArgs ¶
func (*Options) GetFlagCreateIgnoreFiledPath ¶ added in v0.2.5
func (*Options) GetFlagSet ¶
func (*Options) GetLogDebug ¶
func (*Options) GetLogWarning ¶
func (*Options) GetMapMerge ¶
func (*Options) GetOptionUsage ¶ added in v0.2.5
all getter func
func (*Options) GetOptionUsagePoweredBy ¶ added in v0.3.11
func (*Options) GetParseDefault ¶
func (*Options) GetParseMetaKeyFlagFiles ¶ added in v0.2.6
func (*Options) GetReaders ¶
func (*Options) GetReplaceFlagSetUsage ¶ added in v0.2.6
func (*Options) GetStringAlias ¶ added in v0.2.6
func (*Options) GetStringAliasFunc ¶ added in v0.2.6
func (*Options) GetTagName ¶
func (*Options) GetTagNameForDefaultValue ¶ added in v0.2.5
type OptionsInterface ¶
type OptionsInterface interface { OptionsVisitor ApplyOption(...Option) []Option }
OptionsInterface visitor + ApplyOption interface for Options
type OptionsVisitor ¶
type OptionsVisitor interface { GetOptionUsage() string GetFiles() []string GetReaders() []io.Reader GetFlagSet() *flag.FlagSet GetFlagArgs() []string GetEnviron() []string GetErrorHandling() ErrorHandling GetTagName() string GetDecoderConfigOption() []DecoderConfigOption GetMapMerge() bool GetFieldTagConvertor() FieldTagConvertor GetFieldPathRemoved() []string GetDebug() bool GetLogDebug() LogFunc GetLogWarning() LogFunc GetAppLabelList() []string GetEnvBindShouldErrorWhenFailed() bool GetFlagCreateIgnoreFiledPath() []string GetParseDefault() bool GetTagNameForDefaultValue() string GetReplaceFlagSetUsage() bool GetParseMetaKeyFlagFiles() bool GetEnvironPrefix() string GetOptionUsagePoweredBy() string GetErrorUnused() bool GetStringAlias() map[string]string GetStringAliasFunc() map[string]func(s string) string }
OptionsVisitor visitor interface for Options
func AtomicOptions ¶
func AtomicOptions() OptionsVisitor
AtomicOptions return atomic *OptionsVisitor
type Struct ¶
type Struct struct {
// contains filtered or unexported fields
}
Struct Struct类型定义
func NewStruct ¶
func NewStruct(s interface{}, tagName, tagNameDefaultValue string, ff FieldTagConvertor) *Struct
NewStruct 构造Struct类型
type StructFieldPathInfo ¶
type StructFieldPathInfo struct { TagListXConf xfield.TagList Tag reflect.StructTag FieldName string FieldNameList []string DefaultGot bool DefaultString string }
StructFieldPathInfo field信息
type XConf ¶
type XConf struct {
// contains filtered or unexported fields
}
XConf XConf struct
func NewWithoutFlagEnv ¶
NewWithoutFlagEnv 构造新的Xconf,移除FlagSet和Environ解析
func (*XConf) HashStructure ¶
HashStructure 返回指定数据的hash值
func (*XConf) MustSaveToBytes ¶
func (x *XConf) MustSaveToBytes(ct ConfigType) []byte
MustSaveToBytes 将内置解析的数据以字节流返回,需指定ConfigType
func (*XConf) MustSaveToFile ¶
MustSaveToFile 将内置解析的数据dump到文件,根据文件后缀选择codec,如发生错误会panic
func (*XConf) MustSaveToWriter ¶
func (x *XConf) MustSaveToWriter(ct ConfigType, writer io.Writer)
MustSaveToWriter 将内置解析的数据dump到writer,需指定ConfigType,如发生错误会panic
func (*XConf) MustSaveVarToFile ¶
MustSaveVarToFile 将外部传入的valPtr,写入到fileName中,根据文件后缀选择codec,如发生错误会panic
func (*XConf) MustSaveVarToWriter ¶
func (x *XConf) MustSaveVarToWriter(valPtr interface{}, ct ConfigType, writer io.Writer)
MustSaveVarToWriter 将外部传入的valPtr,写入到writer中,类型为ct,如发生错误会panic
func (*XConf) SaveToFile ¶
SaveToFile 将内置解析的数据dump到文件,根据文件后缀选择codec
func (*XConf) SaveToWriter ¶
func (x *XConf) SaveToWriter(ct ConfigType, writer io.Writer) error
SaveToWriter 将内置解析的数据dump到writer,类型为ct
func (*XConf) SaveVarToFile ¶
SaveVarToFile 将外部传入的valPtr,写入到fileName中,根据文件后缀选择codec
func (*XConf) SaveVarToWriter ¶
func (x *XConf) SaveVarToWriter(valPtr interface{}, ct ConfigType, writer io.Writer) error
SaveVarToWriter 将外部传入的valPtr,写入到writer中,类型为ct
func (*XConf) SaveVarToWriterAsYAML ¶ added in v0.3.5
SaveVarToWriterAsYAML 将内置解析的数据解析到yaml,带comment
func (*XConf) StructMapStructure ¶
StructMapStructure 获取传入的s的数据的map[string]interface{}
func (*XConf) UpdateWithEnviron ¶
UpdateWithEnviron 提供环境变量合法配置更新数据,异步通知更新
func (*XConf) UpdateWithFieldPathValues ¶
UpdateWithFieldPathValues 根据字段FieldPath更新数据, 支持的字段类型依赖于xflag
func (*XConf) UpdateWithFiles ¶
UpdateWithFiles 提供files更新数据, 支持的字段类型依赖于xflag
func (*XConf) UpdateWithFlagArgs ¶
UpdateWithFlagArgs 提供FlagSet合法参数更新数据,异步通知更新
func (*XConf) UpdateWithReader ¶
UpdateWithReader 提供files更新数据, 支持的字段类型依赖于xflag
func (*XConf) UsageToWriter ¶ added in v0.2.6
func (*XConf) WatchFieldPath ¶
func (x *XConf) WatchFieldPath(fieldPath string, changed OnFieldUpdated)
WatchFieldPath 关注特定的字段变化
func (*XConf) WatchUpdate ¶
WatchUpdate confPath不会自动绑定env value,如果需要watch的路径与环境变量相关,先通过ParseEnvValue自行解析替换处理错误
func (*XConf) ZeroStructKeysTagList ¶
func (x *XConf) ZeroStructKeysTagList(s interface{}) map[string]StructFieldPathInfo
ZeroStructKeysTagList 获取参数s的空结构的Filed信息
type XConfOptions ¶ added in v0.2.6
type XConfOptions interface {
XConfOptions() []Option
}
XConfOptions 配置实现改接口,xconf会自动获取xconf配置覆盖默认设置