Compare commits
10 Commits
feature/ge
...
46cd353dd6
Author | SHA1 | Date | |
---|---|---|---|
46cd353dd6 | |||
6dd5f7ac62 | |||
e3de2835a9 | |||
f3f064d064 | |||
ef80c6cb79 | |||
c38d16dc28 | |||
59ba4ebfa5 | |||
18351f3b29 | |||
e4cef0855e | |||
da44ae07ab |
15
any.go
15
any.go
@ -43,7 +43,18 @@ type AnyType struct {
|
||||
//
|
||||
// Date : 18:21 2023/6/1
|
||||
func (at *AnyType) IsNil() bool {
|
||||
return at.data == nil
|
||||
if at.data == nil {
|
||||
return true
|
||||
}
|
||||
reflectValue := reflect.ValueOf(at.data)
|
||||
switch reflectValue.Kind() {
|
||||
case reflect.Chan, reflect.Func, reflect.Map,
|
||||
reflect.Pointer, reflect.UnsafePointer,
|
||||
reflect.Interface, reflect.Slice:
|
||||
return reflectValue.IsNil()
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// Type 获取类型
|
||||
@ -109,6 +120,6 @@ func (at *AnyType) ToString() String {
|
||||
case consts.DataTypeBool:
|
||||
return String(fmt.Sprintf("%v", at.data))
|
||||
default:
|
||||
return String(serialize.JSON.MarshalForString(at.data))
|
||||
return String(serialize.JSON.MarshalForStringIgnoreError(at.data))
|
||||
}
|
||||
}
|
||||
|
22
array.go
22
array.go
@ -10,6 +10,7 @@ package wrapper
|
||||
import (
|
||||
"encoding/json"
|
||||
"git.zhangdeman.cn/zhangdeman/op_type"
|
||||
"github.com/tidwall/gjson"
|
||||
"reflect"
|
||||
"strings"
|
||||
)
|
||||
@ -142,3 +143,24 @@ func (at *Array[Bt]) ToStringWithSplit(split string) StringResult {
|
||||
Err: nil,
|
||||
}
|
||||
}
|
||||
|
||||
// ExtraField 提取[]map/[]struct 中的指定字段, 并以list形式返回
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 19:00 2024/10/13
|
||||
func (at *Array[Bt]) ExtraField(fieldName string) String {
|
||||
if at.IsNil() {
|
||||
return String("[]")
|
||||
}
|
||||
byteData, _ := json.Marshal(at.value)
|
||||
res := make([]any, 0)
|
||||
list := gjson.ParseBytes(byteData).Array()
|
||||
for _, item := range list {
|
||||
itemValue := item.Get(fieldName)
|
||||
if itemValue.Exists() {
|
||||
res = append(res, itemValue.Value())
|
||||
}
|
||||
}
|
||||
return String(ArrayType(res).ToString().Value)
|
||||
}
|
||||
|
198
dynamic_struct.go
Normal file
198
dynamic_struct.go
Normal file
@ -0,0 +1,198 @@
|
||||
// Package wrapper ...
|
||||
//
|
||||
// Description : wrapper ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 2024-08-21 16:43
|
||||
package wrapper
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
func NewDynamic() *DynamicStruct {
|
||||
return &DynamicStruct{
|
||||
structFieldList: make([]reflect.StructField, 0),
|
||||
}
|
||||
}
|
||||
|
||||
// DynamicStruct 动态生成数据结构
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 16:48 2024/8/21
|
||||
type DynamicStruct struct {
|
||||
structFieldList []reflect.StructField // 结构体字段列表
|
||||
}
|
||||
|
||||
// AddInt 添加int字段统一Int64
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 17:50 2024/8/21
|
||||
func (ds *DynamicStruct) AddInt(fieldName string, fieldTag string, pkgPath string) {
|
||||
ds.AddStructField(reflect.StructField{
|
||||
Name: fieldName,
|
||||
PkgPath: pkgPath,
|
||||
Type: reflect.TypeOf(int64(0)),
|
||||
Tag: reflect.StructTag(fmt.Sprintf(`json:"%v"`, fieldTag)),
|
||||
})
|
||||
}
|
||||
|
||||
// AddUint 添加uint字段, 统一 uint64
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 17:50 2024/8/21
|
||||
func (ds *DynamicStruct) AddUint(fieldName string, fieldTag string, pkgPath string) {
|
||||
ds.AddStructField(reflect.StructField{
|
||||
Name: fieldName,
|
||||
PkgPath: pkgPath,
|
||||
Type: reflect.TypeOf(uint64(0)),
|
||||
Tag: reflect.StructTag(fieldTag),
|
||||
})
|
||||
}
|
||||
|
||||
// AddString 添加字符串字段
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 17:49 2024/8/21
|
||||
func (ds *DynamicStruct) AddString(fieldName string, fieldTag string, pkgPath string) {
|
||||
ds.AddStructField(reflect.StructField{
|
||||
Name: fieldName,
|
||||
PkgPath: pkgPath,
|
||||
Type: reflect.TypeOf(""),
|
||||
Tag: reflect.StructTag(fmt.Sprintf(`json:"%v"`, fieldTag)),
|
||||
})
|
||||
}
|
||||
|
||||
// AddBool 添加bool字段
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 17:49 2024/8/21
|
||||
func (ds *DynamicStruct) AddBool(fieldName string, fieldTag string, pkgPath string) {
|
||||
ds.AddStructField(reflect.StructField{
|
||||
Name: fieldName,
|
||||
PkgPath: pkgPath,
|
||||
Type: reflect.TypeOf(true),
|
||||
Tag: reflect.StructTag(fmt.Sprintf(`json:"%v"`, fieldTag)),
|
||||
})
|
||||
}
|
||||
|
||||
// AddFloat 添加float字段, 统一 float64
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 17:48 2024/8/21
|
||||
func (ds *DynamicStruct) AddFloat(fieldName string, fieldTag string, pkgPath string) {
|
||||
ds.AddStructField(reflect.StructField{
|
||||
Name: fieldName,
|
||||
PkgPath: pkgPath,
|
||||
Type: reflect.TypeOf(float64(0)),
|
||||
Tag: reflect.StructTag(fmt.Sprintf(`json:"%v"`, fieldTag)),
|
||||
})
|
||||
}
|
||||
|
||||
// AddSlice 添加slice
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 17:47 2024/8/21
|
||||
func (ds *DynamicStruct) AddSlice(fieldName string, fieldTag string, pkgPath string) {
|
||||
ds.AddStructField(reflect.StructField{
|
||||
Name: fieldName,
|
||||
PkgPath: pkgPath,
|
||||
Type: reflect.TypeOf([]any{}),
|
||||
Tag: reflect.StructTag(fieldTag),
|
||||
})
|
||||
}
|
||||
|
||||
// AddMap 添加map字段
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 17:43 2024/8/21
|
||||
func (ds *DynamicStruct) AddMap(fieldName string, fieldTag string, pkgPath string) {
|
||||
ds.AddStructField(reflect.StructField{
|
||||
Name: fieldName,
|
||||
PkgPath: pkgPath,
|
||||
Type: reflect.TypeOf(map[string]any{}),
|
||||
Tag: reflect.StructTag(fieldTag),
|
||||
})
|
||||
}
|
||||
|
||||
// AddAny 添加任意类型字段
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 17:52 2024/8/21
|
||||
func (ds *DynamicStruct) AddAny(fieldName string, fieldTag string, pkgPath string, value any) {
|
||||
if nil == value {
|
||||
// 不能是空指针
|
||||
return
|
||||
}
|
||||
ds.AddStructField(reflect.StructField{
|
||||
Name: fieldName,
|
||||
PkgPath: pkgPath,
|
||||
Type: reflect.TypeOf(value),
|
||||
Tag: reflect.StructTag(fieldTag),
|
||||
})
|
||||
}
|
||||
|
||||
// AddStructField 添加结构体字段
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 17:42 2024/8/21
|
||||
func (ds *DynamicStruct) AddStructField(field reflect.StructField) {
|
||||
if field.Tag == "" {
|
||||
field.Tag = reflect.StructTag(fmt.Sprintf(`json:"%v"`, field.Name))
|
||||
}
|
||||
field.Name = String(field.Name).SnakeCaseToCamel() // 转成大驼峰, 保证对外可访问
|
||||
ds.structFieldList = append(ds.structFieldList, field)
|
||||
}
|
||||
|
||||
// GetStructType 获取结构体的类型
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 16:58 2024/8/21
|
||||
func (ds *DynamicStruct) GetStructType() reflect.Type {
|
||||
return reflect.StructOf(ds.structFieldList)
|
||||
}
|
||||
|
||||
// ToStructDefaultValue 获取结构体的值, 并采用对应类型默认值填充相关字段
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 16:56 2024/8/21
|
||||
func (ds *DynamicStruct) ToStructDefaultValue() any {
|
||||
defer ds.Clear()
|
||||
defaultValue := reflect.New(ds.GetStructType()).Elem().Interface()
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
// ToStructDefaultSliceValue 自动生成结构体列表
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 17:04 2024/8/21
|
||||
func (ds *DynamicStruct) ToStructDefaultSliceValue() any {
|
||||
defer ds.Clear()
|
||||
tSlice := reflect.MakeSlice(reflect.SliceOf(ds.GetStructType()), 0, 0)
|
||||
return reflect.New(tSlice.Type()).Elem().Interface()
|
||||
}
|
||||
|
||||
// Clear 清理
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 17:08 2024/8/21
|
||||
func (ds *DynamicStruct) Clear() {
|
||||
// 清理掉已设置的字段, 不然实例复用会互相影响
|
||||
ds.structFieldList = make([]reflect.StructField, 0)
|
||||
}
|
27
dynamic_struct_test.go
Normal file
27
dynamic_struct_test.go
Normal file
@ -0,0 +1,27 @@
|
||||
// Package wrapper ...
|
||||
//
|
||||
// Description : wrapper ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 2024-08-21 17:56
|
||||
package wrapper
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/mitchellh/mapstructure"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNewDynamic(t *testing.T) {
|
||||
instance := NewDynamic()
|
||||
instance.AddInt("Age", "age", "")
|
||||
instance.AddString("Name", "name", "")
|
||||
defaultVal := instance.ToStructDefaultValue()
|
||||
testMap := map[string]any{
|
||||
"name": "白茶",
|
||||
"age": 18,
|
||||
}
|
||||
_ = mapstructure.Decode(testMap, &defaultVal)
|
||||
fmt.Println(defaultVal)
|
||||
}
|
11
go.mod
11
go.mod
@ -5,14 +5,14 @@ go 1.21
|
||||
toolchain go1.21.4
|
||||
|
||||
require (
|
||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240726024939-e424db29c5c4
|
||||
git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20240311030808-e2a2e6a3c211
|
||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20241104082108-0f97a870bbc3
|
||||
git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20241101082529-28a6c68e38a4
|
||||
git.zhangdeman.cn/zhangdeman/op_type v0.0.0-20240122104027-4928421213c0
|
||||
git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20240618035451-8d48a6bd39dd
|
||||
git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20241104092308-ecb02113459e
|
||||
github.com/axgle/mahonia v0.0.0-20180208002826-3358181d7394
|
||||
github.com/spaolacci/murmur3 v1.1.0
|
||||
github.com/stretchr/testify v1.8.4
|
||||
github.com/tidwall/gjson v1.17.3
|
||||
github.com/stretchr/testify v1.9.0
|
||||
github.com/tidwall/gjson v1.18.0
|
||||
)
|
||||
|
||||
require (
|
||||
@ -21,6 +21,7 @@ require (
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/go-ini/ini v1.67.0 // indirect
|
||||
github.com/mitchellh/go-homedir v1.1.0 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
github.com/mozillazg/go-pinyin v0.20.0 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/tidwall/match v1.1.1 // indirect
|
||||
|
19
go.sum
19
go.sum
@ -10,10 +10,20 @@ git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240612081722-31c64d4d4ce7 h1:QR8vMX
|
||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240612081722-31c64d4d4ce7/go.mod h1:IXXaZkb7vGzGnGM5RRWrASAuwrVSNxuoe0DmeXx5g6k=
|
||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240726024939-e424db29c5c4 h1:mibnyzYbZullK0aTHVASHl3UeoVr8IgytQZsuyv+yEM=
|
||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240726024939-e424db29c5c4/go.mod h1:IXXaZkb7vGzGnGM5RRWrASAuwrVSNxuoe0DmeXx5g6k=
|
||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240823041145-d4df71cf37e5 h1:pmIHln0gWW+5xAB762h3WDsRkZuYLUDndvJDsGMKoOY=
|
||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240823041145-d4df71cf37e5/go.mod h1:IXXaZkb7vGzGnGM5RRWrASAuwrVSNxuoe0DmeXx5g6k=
|
||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20241023090605-10cff9173059 h1:TPAYdTKKUjgxtCnK38d1Tb4teyQp1C7wYHPdR32yZtM=
|
||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20241023090605-10cff9173059/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/easymap v0.0.0-20240130062251-a87a97b0e8d4 h1:93JYY8JLbFcrlq37q/uKyxs2r2e3modsjvfSbnZQ/UI=
|
||||
git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20240130062251-a87a97b0e8d4/go.mod h1:SrtvrQRdzt+8KfYzvosH++gWxo2ShPTzR1m3VQ6uX7U=
|
||||
git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20240311030808-e2a2e6a3c211 h1:I/wOsRpCSRkU9vo1u703slQsmK0wnNeZzsWQOGtIAG0=
|
||||
git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20240311030808-e2a2e6a3c211/go.mod h1:SrtvrQRdzt+8KfYzvosH++gWxo2ShPTzR1m3VQ6uX7U=
|
||||
git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20241024134352-ce2d84d282ba h1:hgajrPZGoDY9P+x6iqcS06pnu5t+N7DOfpmRwb+TZ4s=
|
||||
git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20241024134352-ce2d84d282ba/go.mod h1:V4Dfg1v/JVIZGEKCm6/aehs8hK+Xow1dkL1yiQymXlQ=
|
||||
git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20241101082529-28a6c68e38a4 h1:s6d4b6yY+NaK1AzoBD1pxqsuygEHQz0Oie86c45geDw=
|
||||
git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20241101082529-28a6c68e38a4/go.mod h1:V4Dfg1v/JVIZGEKCm6/aehs8hK+Xow1dkL1yiQymXlQ=
|
||||
git.zhangdeman.cn/zhangdeman/op_type v0.0.0-20240122104027-4928421213c0 h1:gUDlQMuJ4xNfP2Abl1Msmpa3fASLWYkNlqDFF/6GN0Y=
|
||||
git.zhangdeman.cn/zhangdeman/op_type v0.0.0-20240122104027-4928421213c0/go.mod h1:VHb9qmhaPDAQDcS6vUiDCamYjZ4R5lD1XtVsh55KsMI=
|
||||
git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20240110090803-399e964daa0c h1:k7VCn9GfRGTilvdF/TcTFVMDBfKLe3VeGAtMTiDSnS0=
|
||||
@ -22,6 +32,10 @@ git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20240325080031-1f58204e8687 h1:uQc
|
||||
git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20240325080031-1f58204e8687/go.mod h1:gf7SW2TXATgux8pfdFedMkXWv2515OtIIM/5c4atkFw=
|
||||
git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20240618035451-8d48a6bd39dd h1:2Y37waOVCmVvx0Rp8VGEptE2/2JVMImtxB4dKKDk/3w=
|
||||
git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20240618035451-8d48a6bd39dd/go.mod h1:6+7whkCmb4sJDIfH3HxNuXRveaM0gCCNWd2uXZqNtIE=
|
||||
git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20241023104258-2e0a298aa558 h1:ZVJyyDKfYeA3TsN8UOi4IprkouK4wIIfCKe+F9byLWA=
|
||||
git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20241023104258-2e0a298aa558/go.mod h1:/9eicss/Dt9tp2jwZ/4cXDqDKo/Dez+HuT5/NGdqW+s=
|
||||
git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20241104092308-ecb02113459e h1:A045F67AMSqFKGD9kk2uLa+6c/zpmW8vjjSRmSsdjPs=
|
||||
git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20241104092308-ecb02113459e/go.mod h1:XqgER4jDYwskFgj2riJ9XptIjzgYWubY+Zq8iB2WkY0=
|
||||
git.zhangdeman.cn/zhangdeman/util v0.0.0-20231227095334-7eb5cdbf9253 h1:GO3oZa5a2sqwAzGcLDJtQzmshSWRmoP7IDS8bwFqvC4=
|
||||
git.zhangdeman.cn/zhangdeman/util v0.0.0-20231227095334-7eb5cdbf9253/go.mod h1:VpPjBlwz8U+OxZuxzHQBv1aEEZ3pStH6bZvT21ADEbI=
|
||||
git.zhangdeman.cn/zhangdeman/util v0.0.0-20240618042405-6ee2c904644e h1:Q973S6CcWr1ICZhFI1STFOJ+KUImCl2BaIXm6YppBqI=
|
||||
@ -38,6 +52,8 @@ github.com/go-ini/ini v1.67.0 h1:z6ZrTEZqSWOTyH2FlglNbNgARyHG8oLW9gMELqKr06A=
|
||||
github.com/go-ini/ini v1.67.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8=
|
||||
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
|
||||
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
|
||||
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
||||
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||
github.com/mozillazg/go-pinyin v0.20.0 h1:BtR3DsxpApHfKReaPO1fCqF4pThRwH9uwvXzm+GnMFQ=
|
||||
github.com/mozillazg/go-pinyin v0.20.0/go.mod h1:iR4EnMMRXkfpFVV5FMi4FNB6wGq9NV6uDWbUuPhP4Yc=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
@ -46,8 +62,11 @@ github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0b
|
||||
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
|
||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/tidwall/gjson v1.17.3 h1:bwWLZU7icoKRG+C+0PNwIKC6FCJO/Q3p2pZvuP0jN94=
|
||||
github.com/tidwall/gjson v1.17.3/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
|
||||
github.com/tidwall/gjson v1.18.0 h1:FIDeeyB800efLX89e5a8Y0BNH+LOngJyGrIWxG2FKQY=
|
||||
github.com/tidwall/gjson v1.18.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
|
||||
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
|
||||
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
|
||||
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
|
||||
|
2
map.go
2
map.go
@ -39,7 +39,7 @@ func EasyMapWithError(mapData any) (Map, error) {
|
||||
reflectType := reflect.TypeOf(mapData)
|
||||
if reflectType.Kind() != reflect.Map {
|
||||
mapFormatData := make(map[string]any)
|
||||
if err := serialize.JSON.UnmarshalWithNumber(serialize.JSON.MarshalForByte(mapData), &mapFormatData); nil != err {
|
||||
if err := serialize.JSON.UnmarshalWithNumber(serialize.JSON.MarshalForByteIgnoreError(mapData), &mapFormatData); nil != err {
|
||||
return m, errors.New("input data type is " + reflectType.String() + ", can not convert to map")
|
||||
}
|
||||
mapData = mapFormatData
|
||||
|
Reference in New Issue
Block a user