data

package
v3.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 5, 2024 License: Apache-2.0 Imports: 2 Imported by: 9

Documentation

Overview

Package data contains functions for working with unstructured values like []interface or map[string]interface{}. It allows reading/writing to these values without having to convert to structured items.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetValue

func GetValue(data map[string]interface{}, keys ...string) (interface{}, bool)

GetValue works similar to GetValueFromAny, but can only process maps. Kept this way to avoid breaking changes with the previous interface, GetValueFromAny should be used in most cases since that can handle slices as well.

func GetValueFromAny

func GetValueFromAny(data interface{}, keys ...string) (interface{}, bool)

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 GetValueN

func GetValueN(data map[string]interface{}, keys ...string) interface{}

func MergeMaps

func MergeMaps(base, overlay map[string]interface{}) map[string]interface{}

func MergeMapsConcatSlice

func MergeMapsConcatSlice(base, overlay map[string]interface{}) map[string]interface{}

func PutValue

func PutValue(data map[string]interface{}, val interface{}, keys ...string)

PutValue updates the value of a given map at the index specified by keys that denote the path to the value in the nested structure of the map. If there is no current entry at a key, a new map is created for that value.

func RemoveValue

func RemoveValue(data map[string]interface{}, keys ...string) (interface{}, bool)

RemoveValue removes a value from data. Keys should be in order denoting the path to the value in the nested structure of the map. For example, passing []string{"metadata", "annotations"} will make the function remove the "annotations" key from the "metadata" sub-map. Returns the removed value (if any) and a bool indicating if the value was found.

Types

type List

type List []map[string]interface{}

type Object

type Object map[string]interface{}

func Convert

func Convert(obj interface{}) (Object, error)

func New

func New() Object

func (Object) Bool

func (o Object) Bool(key ...string) bool

func (Object) Map

func (o Object) Map(names ...string) Object

func (Object) Set

func (o Object) Set(key string, obj interface{})

func (Object) SetNested

func (o Object) SetNested(obj interface{}, key ...string)

func (Object) Slice

func (o Object) Slice(names ...string) (result []Object)

func (Object) String

func (o Object) String(names ...string) string

func (Object) StringSlice

func (o Object) StringSlice(names ...string) []string

func (Object) Values

func (o Object) Values() (result []Object)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL