From 44de8814d86b99e45563439d12a2b6cf332f094c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Mon, 25 Nov 2024 14:29:19 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E4=BD=BF=E7=94=A8=E6=9E=9A?= =?UTF-8?q?=E4=B8=BE=E5=80=BC=E9=80=82=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- define.go | 12 +++++++----- filter.go | 7 ++++--- go.mod | 4 ++-- go.sum | 4 ++++ 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/define.go b/define.go index e121323..fe2a442 100644 --- a/define.go +++ b/define.go @@ -7,15 +7,17 @@ // Date : 2022-07-04 18:02 package filter +import "git.zhangdeman.cn/zhangdeman/consts/enums" + // MapRule 映射规则 // // Author : go_developer@163.com<白茶清欢> // // Date : 12:21 2022/7/4 type MapRule struct { - SourcePath string `json:"source_path"` // 原路径 - TargetPath string `json:"target_path"` // 目标路径路径 - Required bool `json:"required"` // 必须存在 - DataType string `json:"data_type"` // 数据类型 - DefaultValue string `json:"default_value"` // 默认值, 以字符串传入, 会转换成 DataType + SourcePath string `json:"source_path"` // 原路径 + TargetPath string `json:"target_path"` // 目标路径路径 + Required bool `json:"required"` // 必须存在 + DataType enums.DataType `json:"data_type"` // 数据类型 + DefaultValue string `json:"default_value"` // 默认值, 以字符串传入, 会转换成 DataType } diff --git a/filter.go b/filter.go index 78dd7ff..d6b180b 100644 --- a/filter.go +++ b/filter.go @@ -11,6 +11,7 @@ import ( "encoding/json" "fmt" "git.zhangdeman.cn/zhangdeman/consts" + "git.zhangdeman.cn/zhangdeman/consts/enums" "git.zhangdeman.cn/zhangdeman/serialize" "git.zhangdeman.cn/zhangdeman/wrapper" "reflect" @@ -196,7 +197,7 @@ func (f *filter) Parse(receiver interface{}) error { // Author : go_developer@163.com<白茶清欢> // // Date : 12:25 2022/7/4 -func (f *filter) getValue(dataType string, sourceValue gjson.Result, defaultValue string) (any, error) { +func (f *filter) getValue(dataType enums.DataType, sourceValue gjson.Result, defaultValue string) (any, error) { sourceValueStr := defaultValue if sourceValue.Exists() { str := sourceValue.String() @@ -282,7 +283,7 @@ func (f *filter) getValue(dataType string, sourceValue gjson.Result, defaultValu sliceVal := strVal.ToStringSlice(",") return sliceVal.Value, sliceVal.Err case consts.DataTypeSliceSlice, consts.DataTypeMapAnyAny: - return nil, errors.New(consts.DataTypeSliceSlice + " : data type is not support") + return nil, errors.New(consts.DataTypeSliceSlice.String() + " : data type is not support") case consts.DataTypeSliceMapStringAny: if !sourceValue.IsArray() { return nil, errors.New("data type is not array") @@ -340,6 +341,6 @@ func (f *filter) getValue(dataType string, sourceValue gjson.Result, defaultValu err := strVal.ToStruct(&res) return res, err default: - return nil, errors.New(dataType + " is not support!") + return nil, errors.New(dataType.String() + " is not support!") } } diff --git a/go.mod b/go.mod index eee5a58..3a75536 100644 --- a/go.mod +++ b/go.mod @@ -5,11 +5,11 @@ go 1.21 toolchain go1.21.5 require ( - git.zhangdeman.cn/zhangdeman/consts v0.0.0-20241104082108-0f97a870bbc3 + git.zhangdeman.cn/zhangdeman/consts v0.0.0-20241125061350-1f5050978fc3 git.zhangdeman.cn/zhangdeman/easylock v0.0.0-20230731062340-983985c12eda git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20241108082010-42ae8fe5ebdc git.zhangdeman.cn/zhangdeman/util v0.0.0-20240618042405-6ee2c904644e - git.zhangdeman.cn/zhangdeman/wrapper v0.0.0-20241106102517-46cd353dd617 + git.zhangdeman.cn/zhangdeman/wrapper v0.0.0-20241125062526-91423fb146e0 github.com/pkg/errors v0.9.1 github.com/smartystreets/goconvey v1.8.1 github.com/tidwall/gjson v1.18.0 diff --git a/go.sum b/go.sum index 5b1a258..b618ea9 100644 --- a/go.sum +++ b/go.sum @@ -2,6 +2,8 @@ git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240608115700-4311f44fabf6 h1:3xXT34 git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240608115700-4311f44fabf6/go.mod h1:IXXaZkb7vGzGnGM5RRWrASAuwrVSNxuoe0DmeXx5g6k= git.zhangdeman.cn/zhangdeman/consts v0.0.0-20241104082108-0f97a870bbc3 h1:BiAlBJ+DuRs/xD7nDQD2JT8Oc+V+0Uwt36qZwdXGvzI= git.zhangdeman.cn/zhangdeman/consts v0.0.0-20241104082108-0f97a870bbc3/go.mod h1:IXXaZkb7vGzGnGM5RRWrASAuwrVSNxuoe0DmeXx5g6k= +git.zhangdeman.cn/zhangdeman/consts v0.0.0-20241125061350-1f5050978fc3 h1:/40XIygeSxRhPQc3/7pKGpV5hg8jwrMwh1+YiyCHdNI= +git.zhangdeman.cn/zhangdeman/consts v0.0.0-20241125061350-1f5050978fc3/go.mod h1:IXXaZkb7vGzGnGM5RRWrASAuwrVSNxuoe0DmeXx5g6k= git.zhangdeman.cn/zhangdeman/easylock v0.0.0-20230731062340-983985c12eda h1:bMD6r9gjRy7cO+T4zRQVYAesgIblBdTnhzT1vN5wjvI= git.zhangdeman.cn/zhangdeman/easylock v0.0.0-20230731062340-983985c12eda/go.mod h1:dT0rmHcJ9Z9IqWeMIt7YzR88nKkNV2V3dfG0j9Q6lK0= git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20240311030808-e2a2e6a3c211 h1:I/wOsRpCSRkU9vo1u703slQsmK0wnNeZzsWQOGtIAG0= @@ -22,6 +24,8 @@ git.zhangdeman.cn/zhangdeman/wrapper v0.0.0-20240608120635-588df729e0d3 h1:IDzOa git.zhangdeman.cn/zhangdeman/wrapper v0.0.0-20240608120635-588df729e0d3/go.mod h1:7vFN7QrHLLI/iN7ZrJSU0bw/7TyaYjVQ4+clYuIoRrY= git.zhangdeman.cn/zhangdeman/wrapper v0.0.0-20241106102517-46cd353dd617 h1:4rwv7bYKA4+IQgQiT8yNeM92t+fGd2tR5zD2ixpP6i8= git.zhangdeman.cn/zhangdeman/wrapper v0.0.0-20241106102517-46cd353dd617/go.mod h1:uEuMBRzTlUJ9k3H+PymZWPn1b48U9lJPQ+ZBWmP+O/c= +git.zhangdeman.cn/zhangdeman/wrapper v0.0.0-20241125062526-91423fb146e0 h1:aGQADmQKTF7c8+s3acnn569sTJwjlLhhhZfQ6f4nAH0= +git.zhangdeman.cn/zhangdeman/wrapper v0.0.0-20241125062526-91423fb146e0/go.mod h1:lvVOIrYDvCQHUzBdaOwKSrxT9ubcXQJBsafWMWu+I14= github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0= github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= github.com/axgle/mahonia v0.0.0-20180208002826-3358181d7394 h1:OYA+5W64v3OgClL+IrOD63t4i/RW7RqrAVl9LTZ9UqQ=