structure

package
v2.2.4 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2025 License: MIT Imports: 1 Imported by: 0

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

func StructToMap(input any) map[string]any

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.

Jump to

Keyboard shortcuts

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