unstructured

package
v2.12.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound when a field is not found in an object
	ErrNotFound = errors.New("not found")

	// ErrNilObject when an object is unexpectedly nil
	ErrNilObject = errors.New("nil object")

	// ErrNotObject when a field is not an object
	ErrNotObject = errors.New("not an object")

	// ErrNotArray when a field is not an array
	ErrNotArray = errors.New("not an array")
)

Functions

func AsPath

func AsPath(xpath string) []string

AsPath translates the given simplified xpath expression into a sequence of path entries. This ia very shallow xpath formatter, not full xpath compliant

func Base

func Base(path []string) string

Base returns the base of the given path, namely the last name in the array

func CopyFields

func CopyFields(target, source map[string]any)

CopyFields copies all unstructured fields from an source to a target

func CreateField

func CreateField[T any](obj map[string]any, value T, fields ...string) error

CreateField creates a field with a value at the given path

func Dir

func Dir(path []string) []string

Dir returns the parent path of path

func FieldsOf

func FieldsOf(obj map[string]any) []string

FieldsOf returns the names of the fields at the given obj value

func FromUnstructured

func FromUnstructured(target any, source map[string]any) error

FromUnstructured fills a target value with the field values from an unstructured map

func GetField

func GetField[T any](obj map[string]any, fields ...string) (T, error)

GetField gets the value of a named path within the given unstructured map

func GetFieldObject

func GetFieldObject(obj map[string]any, fields ...string) (map[string]any, error)

GetFieldObject returns the object holding the given field path

func GetOrCreateField

func GetOrCreateField[T any](obj map[string]any, defaultValue T, fields ...string) (T, error)

GetOrCreateField access a field at the given path, it creates the field with the given defaultValue if it did not exist

func RecursiveCreateField

func RecursiveCreateField[T any](obj map[string]any, value T, fields ...string) error

RecursiveCreateField creates a field with a value at the given path, it does create the parent path objects as needed

func ToUnstructured

func ToUnstructured(obj any) (map[string]any, error)

ToUnstructured returns an unstructured map holding the public field values from the original input obj value

Types

This section is empty.

Jump to

Keyboard shortcuts

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