Browse Source

修改函数名

yjp 1 year ago
parent
commit
a5de38209f
2 changed files with 6 additions and 6 deletions
  1. 2 2
      maputils/maputils.go
  2. 4 4
      maputils/maputils_test.go

+ 2 - 2
maputils/maputils.go

@@ -10,7 +10,7 @@ const (
 	pathSeparator = "."
 )
 
-func GetValueInMap(m map[string]any, path string) (any, error) {
+func GetValueByPath(m map[string]any, path string) (any, error) {
 	if m == nil || strings.TrimSpace(path) == "" {
 		return nil, errors.New("没有传递需要查找的数据或路径")
 	}
@@ -72,7 +72,7 @@ func GetValueInMap(m map[string]any, path string) (any, error) {
 	return retValue, nil
 }
 
-func GetValue[K comparable, V any](m map[K]any, key K) (V, bool) {
+func GetValueByKey[K comparable, V any](m map[K]any, key K) (V, bool) {
 	var zeroValue V
 
 	mapValue, ok := m[key]

+ 4 - 4
maputils/maputils_test.go

@@ -11,7 +11,7 @@ func TestGetValueInMap(t *testing.T) {
 		},
 	}
 
-	value, err := GetValueInMap(testMap, "foo1.foo1_sub.[0]")
+	value, err := GetValueByPath(testMap, "foo1.foo1_sub.[0]")
 	if err != nil {
 		t.Fatal(err)
 	}
@@ -20,7 +20,7 @@ func TestGetValueInMap(t *testing.T) {
 		t.Fatal("值不一致")
 	}
 
-	value, err = GetValueInMap(testMap, "foo1.foo1_sub.[1]")
+	value, err = GetValueByPath(testMap, "foo1.foo1_sub.[1]")
 	if err != nil {
 		t.Fatal(err)
 	}
@@ -39,12 +39,12 @@ func TestGetValue(t *testing.T) {
 		},
 	}
 
-	foo1Map, ok := GetValue[string, map[string]any](testMap, "foo1")
+	foo1Map, ok := GetValueByKey[string, map[string]any](testMap, "foo1")
 	if !ok {
 		t.Fatal("取foo1值失败")
 	}
 
-	foo1Sub, ok := GetValue[string, []any](foo1Map, "foo1_sub")
+	foo1Sub, ok := GetValueByKey[string, []any](foo1Map, "foo1_sub")
 	if !ok {
 		t.Fatal("取foo1Sub值失败")
 	}