reflecthelpers

package
v2.7.0 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeepCopyInto

func DeepCopyInto(in client.Object, out client.Object)

DeepCopyInto calls in.DeepCopyInto(out)

func Find

func Find[T comparable](obj interface{}) (set.Set[T], error)

Find finds all the references of the given type on the provided object

func FindConfigMapReferences

func FindConfigMapReferences(obj interface{}) (set.Set[genruntime.ConfigMapReference], error)

FindConfigMapReferences finds all the genruntime.ConfigMapReference's on the provided object

func FindOptionalConfigMapReferences

func FindOptionalConfigMapReferences(obj interface{}) ([]*genruntime.OptionalConfigMapReferencePair, error)

FindOptionalConfigMapReferences finds all the genruntime.ConfigMapReference's on the provided object

func FindPropertiesWithTag

func FindPropertiesWithTag(obj interface{}, tag string) (map[string][]interface{}, error)

FindPropertiesWithTag finds all the properties with the given tag on the specified object and returns a map of the property name to the property value

func FindReferences

func FindReferences(obj interface{}, t reflect.Type) (map[interface{}]struct{}, error)

FindReferences finds references of the given type on the provided object

func FindResourceReferences

func FindResourceReferences(obj interface{}) (set.Set[genruntime.ResourceReference], error)

FindResourceReferences finds all the genruntime.ResourceReference's on the provided object

func FindSecretMaps added in v2.6.0

func FindSecretMaps(obj interface{}) (set.Set[genruntime.SecretMapReference], error)

FindSecretMaps finds all the genruntime.SecretMapReference's on the provided object

func FindSecretReferences

func FindSecretReferences(obj interface{}) (set.Set[genruntime.SecretReference], error)

FindSecretReferences finds all the genruntime.SecretReference's on the provided object

func GetObjectListItems

func GetObjectListItems(listPtr client.ObjectList) ([]client.Object, error)

GetObjectListItems gets the list of items from an ObjectList

func IdentityVisitMap

func IdentityVisitMap(this *ReflectVisitor, it reflect.Value, ctx interface{}) error

IdentityVisitMap is the identity visit function for maps. It visits each key and value in the map.

func IdentityVisitPrimitive

func IdentityVisitPrimitive(this *ReflectVisitor, it reflect.Value, ctx interface{}) error

IdentityVisitPrimitive is the identity visit function for primitive types.

func IdentityVisitPtr

func IdentityVisitPtr(this *ReflectVisitor, it reflect.Value, ctx interface{}) error

IdentityVisitPtr is the identity visit function for pointer types. It dereferences the pointer and visits the type pointed to.

func IdentityVisitSlice

func IdentityVisitSlice(this *ReflectVisitor, it reflect.Value, ctx interface{}) error

IdentityVisitSlice is the identity visit function for slices. It visits each element of the slice.

func IdentityVisitStruct

func IdentityVisitStruct(this *ReflectVisitor, it reflect.Value, ctx interface{}) error

IdentityVisitStruct is the identity visit function for structs. It visits each exported field of the struct.

func IsPrimitiveKind

func IsPrimitiveKind(k reflect.Kind) bool

IsPrimitiveKind returns true if the provided reflect.Kind is for a primitive type, otherwise false.

func SetObjectListItems

func SetObjectListItems(listPtr client.ObjectList, items []client.Object) (returnErr error)

SetObjectListItems gets the list of items from an ObjectList

func SetProperty added in v2.4.0

func SetProperty(obj any, propertyPath string, value any) error

SetProperty sets the property on the provided object to the provided value. obj is the object to modify. propertyPath is a dot-separated path to the property to set. value is the value to set the property to. Returns an error if any of the properties in the path do not exist, if the property is not settable, or if the value provided is incompatible.

func ValueOfPtr

func ValueOfPtr(ptr interface{}) interface{}

ValueOfPtr dereferences a pointer and returns the value the pointer points to. Use this as carefully as you would the * operator TODO: Can we delete this helper later when we have some better code generated functions?

Types

type ReflectVisitor

type ReflectVisitor struct {
	VisitPrimitive func(this *ReflectVisitor, it reflect.Value, ctx interface{}) error
	VisitStruct    func(this *ReflectVisitor, it reflect.Value, ctx interface{}) error
	VisitPtr       func(this *ReflectVisitor, it reflect.Value, ctx interface{}) error
	VisitSlice     func(this *ReflectVisitor, it reflect.Value, ctx interface{}) error
	VisitMap       func(this *ReflectVisitor, it reflect.Value, ctx interface{}) error
}

ReflectVisitor allows traversing an arbitrary object graph.

func NewReflectVisitor

func NewReflectVisitor() *ReflectVisitor

NewReflectVisitor creates an identity ReflectVisitor.

func (*ReflectVisitor) Visit

func (r *ReflectVisitor) Visit(val interface{}, ctx interface{}) error

Visit visits the provided value. The ctx parameter can be used to pass data through the visit hierarchy.

Jump to

Keyboard shortcuts

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