attributes

package
v2.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2023 License: Apache-2.0 Imports: 4 Imported by: 19

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Attributes

type Attributes map[string]apiext.JSON

Attributes provides a way to add a map of arbitrary YAML/JSON objects. +kubebuilder:validation:Type=object +kubebuilder:validation:XPreserveUnknownFields

func (Attributes) AsInterface

func (attributes Attributes) AsInterface(errorHolder *error) interface{}

AsInterface allows returning the whole attributes map... as an interface. When the attributes are not empty, the returned interface will be a map of interfaces.

An optional error holder can be passed as an argument to receive any error that might have occured during the attributes decoding

func (Attributes) Booleans

func (attributes Attributes) Booleans(errorHolder *error) map[string]bool

Booleans allows returning only the attributes whose content is a JSON boolean.

An optional error holder can be passed as an argument to receive any error that might have be raised during the attribute decoding

func (Attributes) Exists

func (attributes Attributes) Exists(key string) bool

Exists returns `true` if the attribute with the given key exists in the attributes map.

func (Attributes) FromBooleanMap

func (attributes Attributes) FromBooleanMap(strings map[string]bool) Attributes

FromBooleanMap allows adding into the current map of attributes all the attributes contained in the given map of booleans

func (Attributes) FromFloatMap

func (attributes Attributes) FromFloatMap(strings map[string]float64) Attributes

FromFloatMap allows adding into the current map of attributes all the attributes contained in the given map of floats

func (Attributes) FromIntegerMap

func (attributes Attributes) FromIntegerMap(strings map[string]int) Attributes

FromIntegerMap allows adding into the current map of attributes all the attributes contained in the given map of integers

func (Attributes) FromInterface

func (attributes Attributes) FromInterface(structure interface{}, errorHolder *error) Attributes

FromInterface allows completing the map of attributes from the given interface. The given interface, and can be any value that supports Json Marshaling and will be marshalled as a JSON object.

This is especially useful to create attributes from well-known, but implementation- dependent Go structures.

An optional error holder can be passed as an argument to receive any error that might have occured during the attributes decoding

func (Attributes) FromMap

func (attributes Attributes) FromMap(strings map[string]interface{}, errorHolder *error) Attributes

FromMap allows adding into the current map of attributes all the attributes contained in the given map of interfaces each attribute of the given map is provided as an interface, and can be any value that supports Json Marshaling.

An optional error holder can be passed as an argument to receive any error that might have occured during the attributes decoding

func (Attributes) FromStringMap

func (attributes Attributes) FromStringMap(strings map[string]string) Attributes

FromStringMap allows adding into the current map of attributes all the attributes contained in the given string map

func (Attributes) Get

func (attributes Attributes) Get(key string, errorHolder *error) interface{}

Get allows returning the attribute with the given key as an interface. The underlying type of the returned interface depends on the JSON/YAML content of the attribute. It can be either a simple type like a string, a float64 or a bool, either a structured type like a map of interfaces or an array of interfaces.

An optional error holder can be passed as an argument to receive any error that might have occurred during the attribute decoding

func (Attributes) GetBoolean

func (attributes Attributes) GetBoolean(key string, errorHolder *error) bool

GetBoolean allows returning the attribute with the given key as a bool. If the attribute JSON/YAML content is not a JSON boolean (or a JSON string that can be converted into a JSON boolean), then the result will be the `false` zero value and an error is raised.

String values can be converted to boolean values according to the following rules:

- strings "1", "t", "T", "TRUE", "true", and "True" will be converted to a `true` boolean

- strings "0, "f", "F", "FALSE", "false", "False" will be converted to a `false` boolean

- any other string value will raise an error.

An optional error holder can be passed as an argument to receive any error that might have be raised during the attribute decoding

func (Attributes) GetInto

func (attributes Attributes) GetInto(key string, into interface{}) error

GetInto allows decoding the attribute with the given key into a given interface. The provided interface should be a pointer to a struct, to an array, or to any simple type.

An error is returned if the provided interface type is not compatible with the attribute content

func (Attributes) GetNumber

func (attributes Attributes) GetNumber(key string, errorHolder *error) float64

GetNumber allows returning the attribute with the given key as a float64. If the attribute JSON/YAML content is not a JSON number (or a JSON string that can be converted into a JSON number), then the result will be the zero value and an error is raised.

An optional error holder can be passed as an argument to receive any error that might have be raised during the attribute decoding

func (Attributes) GetString

func (attributes Attributes) GetString(key string, errorHolder *error) string

GetString allows returning the attribute with the given key as a string. If the attribute JSON/YAML content is not a JSON string (or a primitive type that can be converted into a string), then the result will be the empty string and an error will be raised.

An optional error holder can be passed as an argument to receive any error that might have be raised during the attribute decoding

func (Attributes) Into

func (attributes Attributes) Into(into interface{}) error

Into allows decoding the whole attributes map into a given interface. The provided interface should be either a pointer to a struct, or to a map.

An error is returned if the provided interface type is not compatible with the structure of the attributes

func (Attributes) MarshalJSON

func (attributes Attributes) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling to support free-form attributes

func (Attributes) Numbers

func (attributes Attributes) Numbers(errorHolder *error) map[string]float64

Numbers allows returning only the attributes whose content is a JSON number.

An optional error holder can be passed as an argument to receive any error that might have be raised during the attribute decoding

func (Attributes) Put

func (attributes Attributes) Put(key string, value interface{}, errorHolder *error) Attributes

Put allows adding an attribute to the current map of attributes. The attribute is provided as an interface, and can be any value that supports Json Marshaling.

An optional error holder can be passed as an argument to receive any error that might have occured during the attributes decoding

func (Attributes) PutBoolean

func (attributes Attributes) PutBoolean(key string, value bool) Attributes

PutBoolean allows adding a boolean attribute to the current map of attributes

func (Attributes) PutFloat

func (attributes Attributes) PutFloat(key string, value float64) Attributes

PutFloat allows adding a float attribute to the current map of attributes

func (Attributes) PutInteger

func (attributes Attributes) PutInteger(key string, value int) Attributes

PutInteger allows adding an integer attribute to the current map of attributes

func (Attributes) PutString

func (attributes Attributes) PutString(key string, value string) Attributes

PutString allows adding a string attribute to the current map of attributes

func (Attributes) Strings

func (attributes Attributes) Strings(errorHolder *error) map[string]string

Strings allows returning only the attributes whose content is a JSON string.

An optional error holder can be passed as an argument to receive any error that might have be raised during the attribute decoding

func (*Attributes) UnmarshalJSON

func (attributes *Attributes) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshalling to support free-form attributes

type KeyNotFoundError

type KeyNotFoundError struct {
	Key string
}

KeyNotFoundError returns an error if no key is found for the attribute

func (*KeyNotFoundError) Error

func (e *KeyNotFoundError) Error() string

Jump to

Keyboard shortcuts

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