values

package
v1.0.11 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Values

type Values map[string]interface{}

Values holds an arbitrary tree-like data structure, such as parsed JSON or YAML. It can be used to represent Helm-like values.

You can use convenient accessors to work with this data structure.

Note: Some use-cases, including Helm SDK, make assumptions about the data type of the embedded lists and objects. To avoid any error or an unexpected behavior use `[]interface{}` for lists and `map[string]interface{}` for nested objects.

func FromYAML

func FromYAML(data []byte) (Values, error)

func FromYAMLFile

func FromYAMLFile(path string) (Values, error)

func (Values) AddHelmValue

func (v Values) AddHelmValue(key, value string) error

AddHelmValue sets the specified value using Helm style key and value format. This is similar to `--set key=value` command argument of Helm. It does not support multiple keys and values. It returns an error if it can not parse the key or assign the value.

func (Values) AsMap

func (v Values) AsMap() map[string]interface{}

AsMap returns the underlying map. This maybe be useful for external libraries.

func (Values) Coalesce

func (v Values) Coalesce(newValues Values)

Coalesce uses Helm-style coalesce to merge the content of another data structure.

Coalesce can traverse nested values. As opposed to merge, it only inserts the missing key-value pairs and does not override the existing keys.

It uses Helm SDK coalesce function and does not return an error when fails to merge specific entries. Therefore it may lead to an incorrect output.

func (Values) GetBool

func (v Values) GetBool(key string, defaultValue ...bool) bool

GetBool retrieves the value of type `bool` that is addressed with a dot-separated key, e.g. `x.y.z`. The key format does not support array indexing.

If the key does not exist or its type is not `bool` it will return the optional `defaultValue` or `false`.

Use `HasKey` to check if the `key` exist.

func (Values) GetString

func (v Values) GetString(key string, defaultValue ...string) string

GetString retrieves the value of type `string` that is addressed with a dot-separated key, e.g. `x.y.z`. The key format does not support array indexing.

If the key does not exist it will return the optional `defaultValue` or an empty string. When the key exists but its type is not `string` it tries to format it as `string`. If it fails it will return either the `defaultValue` or an empty string.

Use `HasKey` to check if the `key` exist.

func (Values) GetValue

func (v Values) GetValue(key string) (interface{}, error)

GetValue retrieves the value that is addressed with a dot-separated key, e.g. `x.y.z`. The key format does not support array indexing.

It will return an error, if the key does not exist or can not be traversed, for example nested keys of a leaf node of the tree.

func (Values) HasKey

func (v Values) HasKey(key string) bool

HasKey checks if a specific key exists. The `key` is in dot-separated format and it does not support array indexing. When it returns `true` the getter methods, e.g. `GetValue`, can successfully retrieve the associated value of the key.

func (Values) Merge

func (v Values) Merge(newValues Values) (Values, error)

Merge uses deep copy to merge the content of another data structure. It overrides the existing keys with their associated new values and copies the missing keys.

func (Values) SetValue

func (v Values) SetValue(key string, value interface{}) error

SetValue set the value that is addressed with a dot-separated key, e.g. `x.y.z`. The key format does not support array indexing.

It does not do any type checking and will override the targeted element with the provided value. It will create any intermediate nested object that doesn't exist. But it will return an error when the key can not be traversed, for example nested keys of a leaf node of the tree.

Jump to

Keyboard shortcuts

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