|
@@ -10,6 +10,12 @@ const (
|
|
|
pathSeparator = "."
|
|
|
)
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
func GetValueByPath(m map[string]any, path string) (any, error) {
|
|
|
if m == nil || strings.TrimSpace(path) == "" {
|
|
|
return nil, errors.New("没有传递需要查找的数据或路径")
|
|
@@ -51,7 +57,7 @@ func GetValueByPath(m map[string]any, path string) (any, error) {
|
|
|
} else {
|
|
|
findMap, ok := currentFind.(map[string]any)
|
|
|
if !ok {
|
|
|
- return nil, errors.New("对应map路径的值不是map: " + pathPart)
|
|
|
+ return nil, errors.New("对应map路径的值不是map[string]any: " + pathPart)
|
|
|
}
|
|
|
|
|
|
value, ok := findMap[pathPart]
|
|
@@ -72,6 +78,14 @@ func GetValueByPath(m map[string]any, path string) (any, error) {
|
|
|
return retValue, nil
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
func GetValueByKey[K comparable, V any](m map[K]any, key K) (V, bool) {
|
|
|
var zeroValue V
|
|
|
|