diff --git a/pkg/data/values.go b/pkg/data/values.go index a0f07f42..61ca9e69 100644 --- a/pkg/data/values.go +++ b/pkg/data/values.go @@ -28,12 +28,18 @@ func GetValueN(data map[string]interface{}, keys ...string) interface{} { return val } -// GetValue retrieves a value from the provided collection, which must be a map[string]interface or a []interface. +// GetValue works the same as GetValueFromAny. Kept this way to avoid breaking changes with the previous interface, +// GetValueFromAny should be used directly in most cases. +func GetValue(data map[string]interface{}, keys ...string) (interface{}, bool) { + return GetValueFromAny(data, keys...) +} + +// GetValueFromAny retrieves a value from the provided collection, which must be a map[string]interface or a []interface. // Keys are always strings. // For a map, a key denotes the key in the map whose value we want to retrieve. // For the slice, it denotes the index (starting at 0) of the value we want to retrieve. // Returns the retrieved value (if any) and a bool indicating if the value was found. -func GetValue(data interface{}, keys ...string) (interface{}, bool) { +func GetValueFromAny(data interface{}, keys ...string) (interface{}, bool) { for i, key := range keys { if i == len(keys)-1 { if dataMap, ok := data.(map[string]interface{}); ok { diff --git a/pkg/data/values_test.go b/pkg/data/values_test.go index a3a1a5ab..327459d0 100644 --- a/pkg/data/values_test.go +++ b/pkg/data/values_test.go @@ -6,7 +6,7 @@ import ( "github.com/stretchr/testify/assert" ) -func TestGetValue(t *testing.T) { +func TestGetValueFromAny(t *testing.T) { t.Parallel() tests := []struct { name string @@ -216,7 +216,7 @@ func TestGetValue(t *testing.T) { test := test t.Run(test.name, func(t *testing.T) { t.Parallel() - gotValue, gotSuccess := GetValue(test.data, test.keys...) + gotValue, gotSuccess := GetValueFromAny(test.data, test.keys...) assert.Equal(t, test.wantValue, gotValue) assert.Equal(t, test.wantSuccess, gotSuccess) })