From a56574ff6537f317c7264fdc8e79bd3f63dba8d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Thu, 21 Nov 2024 14:22:09 +0800 Subject: [PATCH] change easymap -> map --- easymap.go | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/easymap.go b/easymap.go index cbd2a56..a16d233 100644 --- a/easymap.go +++ b/easymap.go @@ -10,7 +10,6 @@ package wrapper import ( "encoding/json" "errors" - "git.zhangdeman.cn/zhangdeman/easymap" "git.zhangdeman.cn/zhangdeman/serialize" "github.com/tidwall/gjson" "reflect" @@ -21,7 +20,7 @@ import ( // Author : go_developer@163.com<白茶清欢> // // Date : 15:02 2023/8/10 -func EasyMap(mapData any) easymap.EasyMap { +func EasyMap(mapData any) Map { m, _ := EasyMapWithError(mapData) return m } @@ -31,24 +30,23 @@ func EasyMap(mapData any) easymap.EasyMap { // Author : go_developer@163.com<白茶清欢> // // Date : 15:06 2023/8/10 -func EasyMapWithError(mapData any) (easymap.EasyMap, error) { +func EasyMapWithError(mapData any) (Map, error) { if nil == mapData { - return easymap.NewNormal(), nil + return map[string]any{}, nil } - m := easymap.NewNormal() reflectType := reflect.TypeOf(mapData) if reflectType.Kind() != reflect.Map { mapFormatData := make(map[string]any) 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") + return mapFormatData, errors.New("input data type is " + reflectType.String() + ", can not convert to map") } - mapData = mapFormatData + return mapFormatData, nil } - + m := Map(map[string]any{}) reflectValue := reflect.ValueOf(mapData).MapRange() for reflectValue.Next() { // 循环提取相关值 - m.Set(reflectValue.Key().Interface(), reflectValue.Value().Interface()) + _ = m.Set(reflectValue.Key().String(), reflectValue.Value().Interface()) } return m, nil } @@ -58,7 +56,7 @@ func EasyMapWithError(mapData any) (easymap.EasyMap, error) { // Author : go_developer@163.com<白茶清欢> // // Date : 16:11 2023/8/10 -func EasyMapFromStruct(data any) easymap.EasyMap { +func EasyMapFromStruct(data any) Map { byteData, _ := json.Marshal(data) return EasyMapFromByte(byteData) } @@ -68,7 +66,7 @@ func EasyMapFromStruct(data any) easymap.EasyMap { // Author : go_developer@163.com<白茶清欢> // // Date : 16:12 2023/8/10 -func EasyMapFromString(data string) easymap.EasyMap { +func EasyMapFromString(data string) Map { return EasyMapFromByte([]byte(data)) } @@ -77,11 +75,11 @@ func EasyMapFromString(data string) easymap.EasyMap { // Author : go_developer@163.com<白茶清欢> // // Date : 16:12 2023/8/10 -func EasyMapFromByte(data []byte) easymap.EasyMap { - res := easymap.NewNormal() +func EasyMapFromByte(data []byte) Map { + res := Map(map[string]any{}) jsonRes := gjson.Parse(string(data)) jsonRes.ForEach(func(key, value gjson.Result) bool { - res.Set(key.Value(), value.Value()) + _ = res.Set(key.String(), value.Value()) return true }) return res