reflect

package
v1.0.0-rc.3 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: MIT Imports: 5 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ReflectRegistry

type ReflectRegistry struct {
	// contains filtered or unexported fields
}

func NewRegistry

func NewRegistry() *ReflectRegistry

NewRegistry creates a new instance of reflect registry.

func (*ReflectRegistry) DeepCopy

func (rr *ReflectRegistry) DeepCopy(value any) (any, error)

DeepCopy performs a deep copy of 'value' and panics if copying fails. It relies on MustDeepCopy to perform the copy and handle errors internally.

Parameters:

value any - the element to be deeply copied.

Returns:

any - a deep copy of 'value'.
error - when 'value' is nil.

For an example of this function in a Go template, refer to Sprout Documentation: deepCopy.

func (*ReflectRegistry) DeepEqual

func (rr *ReflectRegistry) DeepEqual(x, y any) bool

DeepEqual determines if two variables, 'x' and 'y', are deeply equal. It uses reflect.DeepEqual to evaluate equality.

Parameters:

x, y any - the variables to be compared.

Returns:

bool - true if 'x' and 'y' are deeply equal, false otherwise.

For an example of this function in a Go template, refer to Sprout Documentation: deepEqual.

func (*ReflectRegistry) HasField added in v0.6.0

func (rr *ReflectRegistry) HasField(name string, value any) (bool, error)

HasField checks whether a struct has a field with a given name.

Parameters:

name string - the name of the field that is being checked.
value any - the struct that is being checked.

Returns:

bool - true if the struct 'value' contains a field with the name 'name', false otherwise.
error - when the last argument is not a struct.

For an example of this function in a Go template, refer to Sprout Documentation: hasField.

func (*ReflectRegistry) KindIs

func (rr *ReflectRegistry) KindIs(target string, value any) (bool, error)

KindIs compares the kind of 'value' to a target kind string 'target'. It returns true if the kind of 'value' matches the 'target'.

Parameters:

target string - the string representation of the kind to check against.
value any - the variable whose kind is being checked.

Returns:

bool - true if 'value's kind is 'target', false otherwise.
error - when 'value' is nil.

For an example of this function in a Go template, refer to Sprout Documentation: kindIs.

func (*ReflectRegistry) KindOf

func (rr *ReflectRegistry) KindOf(value any) (string, error)

KindOf returns the kind of 'value' as a string.

Parameters:

value any - the variable whose kind is being determined.

Returns:

string - the string representation of 'value's kind.
error - when 'value' is nil.

For an example of this function in a Go template, refer to Sprout Documentation: kindOf.

func (*ReflectRegistry) LinkHandler

func (rr *ReflectRegistry) LinkHandler(fh sprout.Handler) error

LinkHandler links the handler to the registry at runtime.

func (*ReflectRegistry) RegisterAliases added in v0.6.0

func (rr *ReflectRegistry) RegisterAliases(aliasesMap sprout.FunctionAliasMap) error

func (*ReflectRegistry) RegisterFunctions

func (rr *ReflectRegistry) RegisterFunctions(funcsMap sprout.FunctionMap) error

RegisterFunctions registers all functions of the registry.

func (*ReflectRegistry) RegisterNotices added in v0.6.0

func (rr *ReflectRegistry) RegisterNotices(notices *[]sprout.FunctionNotice) error

func (*ReflectRegistry) TypeIs

func (rr *ReflectRegistry) TypeIs(target string, value any) bool

TypeIs compares the type of 'value' to a target type string 'target'. It returns true if the type of 'value' matches the 'target'.

Parameters:

target string - the string representation of the type to check against.
value any - the variable whose type is being checked.

Returns:

bool - true if 'value' is of type 'target', false otherwise.

For an example of this function in a Go template, refer to Sprout Documentation: typeIs.

func (*ReflectRegistry) TypeIsLike

func (rr *ReflectRegistry) TypeIsLike(target string, value any) bool

TypeIsLike compares the type of 'value' to a target type string 'target', including a wildcard '*' prefix option. It returns true if 'value' matches 'target' or '*target'. Useful for checking if a variable is of a specific type or a pointer to that type.

Parameters:

target string - the string representation of the type or its wildcard version.
value any - the variable whose type is being checked.

Returns:

bool - true if the type of 'value' matches 'target' or '*'+target, false otherwise.

For an example of this function in a Go template, refer to Sprout Documentation: typeIsLike.

func (*ReflectRegistry) TypeOf

func (rr *ReflectRegistry) TypeOf(value any) string

TypeOf returns the type of 'value' as a string.

Parameters:

value any - the variable whose type is being determined.

Returns:

string - the string representation of 'value's type.

For an example of this function in a Go template, refer to Sprout Documentation: typeOf.

func (*ReflectRegistry) UID

func (rr *ReflectRegistry) UID() string

UID returns the unique identifier of the registry.

Jump to

Keyboard shortcuts

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