Skip to content

Commit

Permalink
Adding wrapper for GetValue
Browse files Browse the repository at this point in the history
Adds a wrapper for GetValue so that the new function doesn't result in a
breaking change according to semver.
  • Loading branch information
MbolotSuse committed Feb 21, 2024
1 parent 1592712 commit ebe40d5
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pkg/data/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit ebe40d5

Please sign in to comment.