Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CopyExportedFields ¶
func CopyExportedFields(dst, src any)
CopyExportedFields copies all exported fields from src to dst, regardless of their current values. Useful for copying full configurations or cloning objects.
Note: Unexported fields (lowercase) will be ignored.
func MergeZeroFields ¶
func MergeZeroFields(dst, src any)
MergeZeroFields copies non-zero fields from src to dst, but only for fields in dst that are currently zero. dst and src must be pointers to structs of the same type.
Example:
MergeZeroFields(&userConfig, &defaultConfig)
Only fields in userConfig that are zero-valued will be replaced by corresponding values from defaultConfig.
func StructToMap ¶
StructToMap converts an exported struct (or a pointer to one) into a map[string]any. Only exported fields will be included in the map.
Useful for logging, serializing, or dynamic field access.
Example:
m := StructToMap(user) fmt.Println(m["Name"], m["Active"])
func ZeroStruct ¶
func ZeroStruct(v any)
ZeroStruct resets all settable fields in a struct to their zero value. Takes a pointer to a struct.
Example:
ZeroStruct(&config) // config.Name = "", config.Count = 0, config.Enabled = false, etc.
Types ¶
This section is empty.