Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeepCopy ¶
DeepCopy performs a deep copy from the source reflect.Value `src` to the destination reflect.Value `dst`.
It recursively copies all fields, including unexported ones, and supports structs, slices, maps, pointers, arrays, and interfaces. It does not support functions or channels.
func HackField ¶
HackField returns an addressable reflect.Value for the struct field at the given index, even if the field is unexported (private).
Like HackFieldByName, this function uses unsafe.Pointer to bypass Go's visibility restrictions. It should be used with caution, as it breaks encapsulation and may be incompatible with future Go versions.
func HackFieldByName ¶
HackFieldByName returns an addressable `reflect.Value` for the specified field name of a struct, even if the field is unexported (private).
This function uses unsafe.Pointer to bypass Go's visibility restrictions, allowing direct access to unexported struct fields. It should be used with caution, as it breaks encapsulation and may not be compatible with future versions of Go.
Example:
type Foo struct { bar int }
f := Foo{bar: 42}
v := HackFieldByName(f, "bar")
v.SetInt(100) // Successfully modifies the unexported field
Types ¶
This section is empty.