Documentation ¶
Index ¶
- type ReflectRegistry
- func (rr *ReflectRegistry) DeepCopy(element any) (any, error)
- func (rr *ReflectRegistry) DeepEqual(x, y any) bool
- func (rr *ReflectRegistry) HasField(name string, src any) (bool, error)
- func (rr *ReflectRegistry) KindIs(target string, src any) (bool, error)
- func (rr *ReflectRegistry) KindOf(src any) (string, error)
- func (rr *ReflectRegistry) LinkHandler(fh sprout.Handler) error
- func (rr *ReflectRegistry) RegisterAliases(aliasesMap sprout.FunctionAliasMap) error
- func (rr *ReflectRegistry) RegisterFunctions(funcsMap sprout.FunctionMap) error
- func (rr *ReflectRegistry) RegisterNotices(notices *[]sprout.FunctionNotice) error
- func (rr *ReflectRegistry) TypeIs(target string, src any) bool
- func (rr *ReflectRegistry) TypeIsLike(target string, src any) bool
- func (rr *ReflectRegistry) TypeOf(src any) string
- func (rr *ReflectRegistry) Uid() string
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(element any) (any, error)
DeepCopy performs a deep copy of 'element' and panics if copying fails. It relies on MustDeepCopy to perform the copy and handle errors internally.
Parameters:
element any - the element to be deeply copied.
Returns:
any - a deep copy of 'element'. error - when 'element' is nil.
Example:
{{ {"name":"John"} | deepCopy }} // Output: {"name":"John"}
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.
Example:
{{ {"a":1}, {"a":1} | deepEqual }} // Output: true
func (*ReflectRegistry) HasField ¶ added in v0.6.0
func (rr *ReflectRegistry) HasField(name string, src 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. src any - the struct that is being checked.
Returns:
bool - true if the struct 'src' contains a field with the name 'name', false otherwise. error - when the last argument is not a struct.
Example:
{{ hasField "someExistingField" .someStruct }} // Output: true {{ hasField "someNonExistingField" .someStruct }} // Output: false
func (*ReflectRegistry) KindIs ¶
func (rr *ReflectRegistry) KindIs(target string, src any) (bool, error)
KindIs compares the kind of 'src' to a target kind string 'target'. It returns true if the kind of 'src' matches the 'target'.
Parameters:
target string - the string representation of the kind to check against. src any - the variable whose kind is being checked.
Returns:
bool - true if 'src's kind is 'target', false otherwise. error - when 'src' is nil.
Example:
{{ "int", 42 | kindIs }} // Output: true
func (*ReflectRegistry) KindOf ¶
func (rr *ReflectRegistry) KindOf(src any) (string, error)
KindOf returns the kind of 'src' as a string.
Parameters:
src any - the variable whose kind is being determined.
Returns:
string - the string representation of 'src's kind. error - when 'src' is nil.
Example:
{{ 42 | kindOf }} // Output: "int"
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, src any) bool
TypeIs compares the type of 'src' to a target type string 'target'. It returns true if the type of 'src' matches the 'target'.
Parameters:
target string - the string representation of the type to check against. src any - the variable whose type is being checked.
Returns:
bool - true if 'src' is of type 'target', false otherwise.
Example:
{{ "int", 42 | typeIs }} // Output: true
func (*ReflectRegistry) TypeIsLike ¶
func (rr *ReflectRegistry) TypeIsLike(target string, src any) bool
TypeIsLike compares the type of 'src' to a target type string 'target', including a wildcard '*' prefix option. It returns true if 'src' 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. src any - the variable whose type is being checked.
Returns:
bool - true if the type of 'src' matches 'target' or '*'+target, false otherwise.
Example:
{{ "*int", 42 | typeIsLike }} // Output: true
func (*ReflectRegistry) TypeOf ¶
func (rr *ReflectRegistry) TypeOf(src any) string
TypeOf returns the type of 'src' as a string.
Parameters:
src any - the variable whose type is being determined.
Returns:
string - the string representation of 'src's type.
Example:
{{ 42 | typeOf }} // Output: "int"
func (*ReflectRegistry) Uid ¶
func (rr *ReflectRegistry) Uid() string
Uid returns the unique identifier of the registry.