From 07b5f74487a74de9348366dd1ea38ccb9e2a1a0b Mon Sep 17 00:00:00 2001 From: "zhengyang.zhu" Date: Mon, 30 Sep 2024 18:44:00 +0800 Subject: [PATCH] feat: use github.com/sandwich-go/mapstructure --- README-en.md | 2 +- README.md | 2 +- gen_options_optiongen.go | 6 +++--- go.mod | 4 +--- go.sum | 4 ++-- mapstructure.go | 2 +- option.go | 3 ++- xconf.go | 2 +- 8 files changed, 12 insertions(+), 13 deletions(-) diff --git a/README-en.md b/README-en.md index 07c2815..a0f5894 100644 --- a/README-en.md +++ b/README-en.md @@ -154,7 +154,7 @@ func SaveVarToWriterAsYAML(valPtr interface{}, writer io.Writer) error - `WithTagNameDefaultValue`: The Tag name used for the default value, default `default`. - `WithParseDefault`: whether to parse the default value, default true, recommended to use [optiongen](https://github.com/timestee/optiongen) to generate the default configuration data - `WithDebug`: debug mode, will output detailed log of parsing process -- `WithDecoderConfigOption`: adjust the mapstructure parameter, `xconf` uses [mapstructure](https://github.com/mitchellh/mapstructure) for type conversion +- `WithDecoderConfigOption`: adjust the mapstructure parameter, `xconf` uses [mapstructure](https://github.com/sandwich-go/mapstructure) for type conversion - `FieldPathDeprecated`: deprecated configuration, no error will be reported when parsing, but a warning log will be printed - `ErrEnvBindNotExistWithoutDefault`: Error when EnvBind if the specified key does not exist in Env and no default value is specified - `FieldFlagSetCreateIgnore`: The specified `FieldPath` or type name will not print the warning log when there is no Flag Provider. diff --git a/README.md b/README.md index 477190c..d763431 100644 --- a/README.md +++ b/README.md @@ -156,7 +156,7 @@ func SaveVarToWriterAsYAML(valPtr interface{}, writer io.Writer) error - `WithTagNameDefaultValue`: 默认值使用的Tag名称 ,默认`default` - `WithParseDefault`:是否解析默认值,默认true,推荐使用[optiongen](https://github.com/timestee/optiongen)生成默认配置数据 - `WithDebug`: 调试模式,会输出详细的解析流程日志 -- `WithDecoderConfigOption`: 调整mapstructure参数,`xconf`使用[mapstructure](https://github.com/mitchellh/mapstructure)进行类型转换 +- `WithDecoderConfigOption`: 调整mapstructure参数,`xconf`使用[mapstructure](https://github.com/sandwich-go/mapstructure)进行类型转换 - `FieldPathDeprecated`: 弃用的配置,解析时不会报错,但会打印warning日志 - `ErrEnvBindNotExistWithoutDefault`: EnvBind时如果Env中不存在指定的key而且没有指定默认值时报错 - `FieldFlagSetCreateIgnore`: 指定的`FieldPath`或者类型名在没有Flag Provider的时候,不打印报警日志 diff --git a/gen_options_optiongen.go b/gen_options_optiongen.go index 986da78..cd13b50 100644 --- a/gen_options_optiongen.go +++ b/gen_options_optiongen.go @@ -33,8 +33,8 @@ type Options struct { 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/mitchellh/mapstructure") - DecoderConfigOption []DecoderConfigOption `xconf:"decoder_config_option" usage:"xconf内部依赖mapstructure,改方法用户用户层自定义mapstructure解析参数,参考:https://github.com/mitchellh/mapstructure"` + // annotation@DecoderConfigOption(comment="xconf内部依赖mapstructure,改方法用户用户层自定义mapstructure解析参数,参考:https://github.com/sandwich-go/mapstructure") + DecoderConfigOption []DecoderConfigOption `xconf:"decoder_config_option" usage:"xconf内部依赖mapstructure,改方法用户用户层自定义mapstructure解析参数,参考:https://github.com/sandwich-go/mapstructure"` // annotation@MapMerge(comment="map是否开启merge模式,详情见文档") MapMerge bool `xconf:"map_merge" usage:"map是否开启merge模式,详情见文档"` // annotation@FieldTagConvertor(comment="字段名转换到FiledPath时优先使用TagName指定的名称,否则使用该函数转换") @@ -174,7 +174,7 @@ func WithTagName(v string) Option { } } -// WithDecoderConfigOption xconf内部依赖mapstructure,改方法用户用户层自定义mapstructure解析参数,参考:https://github.com/mitchellh/mapstructure +// WithDecoderConfigOption xconf内部依赖mapstructure,改方法用户用户层自定义mapstructure解析参数,参考:https://github.com/sandwich-go/mapstructure func WithDecoderConfigOption(v ...DecoderConfigOption) Option { return func(cc *Options) Option { previous := cc.DecoderConfigOption diff --git a/go.mod b/go.mod index 47cdc76..636df75 100644 --- a/go.mod +++ b/go.mod @@ -7,11 +7,9 @@ require ( github.com/kr/pretty v0.1.0 // indirect github.com/mattn/go-runewidth v0.0.13 github.com/mitchellh/hashstructure/v2 v2.0.2 - github.com/mitchellh/mapstructure v1.4.3 + github.com/sandwich-go/mapstructure v1.6.0 github.com/smartystreets/goconvey v1.7.2 golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b ) - -replace github.com/mitchellh/mapstructure => github.com/sandwich-go/mapstructure v1.4.4-0.20220311064023-afa1d0e26119 diff --git a/go.sum b/go.sum index 9dbbb1c..fd832d5 100644 --- a/go.sum +++ b/go.sum @@ -15,8 +15,8 @@ github.com/mitchellh/hashstructure/v2 v2.0.2 h1:vGKWl0YJqUNxE8d+h8f6NJLcCJrgbhC4 github.com/mitchellh/hashstructure/v2 v2.0.2/go.mod h1:MG3aRVU/N29oo/V/IhBX8GR/zz4kQkprJgF2EVszyDE= github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= -github.com/sandwich-go/mapstructure v1.4.4-0.20220311064023-afa1d0e26119 h1:CNkHX8WVOJk68EdASU4YRtC4P/hqPCh5WdrHKlFa3KQ= -github.com/sandwich-go/mapstructure v1.4.4-0.20220311064023-afa1d0e26119/go.mod h1:F47FfLZAp8P5fA56KOdW5+Eks8qaa4yfpf49SVSiJ0U= +github.com/sandwich-go/mapstructure v1.6.0 h1:FwXGUFVBAkN8CUws4jmV4+Nmg7fEKq/KeQTPZl5agSc= +github.com/sandwich-go/mapstructure v1.6.0/go.mod h1:F47FfLZAp8P5fA56KOdW5+Eks8qaa4yfpf49SVSiJ0U= github.com/smartystreets/assertions v1.2.0 h1:42S6lae5dvLc7BrLu/0ugRtcFVjoJNMC/N3yZFZkDFs= github.com/smartystreets/assertions v1.2.0/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo= github.com/smartystreets/goconvey v1.7.2 h1:9RBaZCeXEQ3UselpuwUQHltGVXvdwm6cv1hgR6gDIPg= diff --git a/mapstructure.go b/mapstructure.go index b1668fa..bf99ccb 100644 --- a/mapstructure.go +++ b/mapstructure.go @@ -3,7 +3,7 @@ package xconf import ( "reflect" - "github.com/mitchellh/mapstructure" + "github.com/sandwich-go/mapstructure" ) // DecoderConfigOption A DecoderConfigOption can be passed to Unmarshal to configure mapstructure.DecoderConfig options diff --git a/option.go b/option.go index 1d09c73..f07b029 100644 --- a/option.go +++ b/option.go @@ -36,6 +36,7 @@ xconf-providers: https://github.com/sandwich-go/xconf-providers var powerBy = `Powered by: https://github.com/sandwich-go/xconf` // OptionsOptionDeclareWithDefault go-lint +// //go:generate optiongen --option_with_struct_name=false --xconf=true --usage_tag_name=usage func OptionsOptionDeclareWithDefault() interface{} { return map[string]interface{}{ @@ -54,7 +55,7 @@ func OptionsOptionDeclareWithDefault() interface{} { "ErrorHandling": (ErrorHandling)(PanicOnError), // annotation@TagName(comment="xconf使用的字段TAG名称,默认:xconf") "TagName": string(DefaultTagName), - // annotation@DecoderConfigOption(comment="xconf内部依赖mapstructure,改方法用户用户层自定义mapstructure解析参数,参考:https://github.com/mitchellh/mapstructure") + // annotation@DecoderConfigOption(comment="xconf内部依赖mapstructure,改方法用户用户层自定义mapstructure解析参数,参考:https://github.com/sandwich-go/mapstructure") "DecoderConfigOption": []DecoderConfigOption(nil), // annotation@MapMerge(comment="map是否开启merge模式,详情见文档") "MapMerge": false, diff --git a/xconf.go b/xconf.go index 0b6e73d..cf1365c 100644 --- a/xconf.go +++ b/xconf.go @@ -12,7 +12,7 @@ import ( "reflect" "github.com/mitchellh/hashstructure/v2" - "github.com/mitchellh/mapstructure" + "github.com/sandwich-go/mapstructure" "github.com/sandwich-go/xconf/xflag" "github.com/sandwich-go/xconf/xutil" )