struct_utils

package
v1.1.15 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertStruct added in v1.0.15

func ConvertStruct(src, dest interface{}) error

ConvertStruct 递归地将源结构体(src)的字段值复制到目标结构体指针(dest)中。 src 支持结构体或结构体指针,dest 必须为结构体指针。

func ConvertTo added in v1.1.15

func ConvertTo[T any](value any) (T, error)

func MapToStruct

func MapToStruct(data map[string]any, result any) error

MapToStruct 将 map 转换为结构体

func MarshalData added in v1.0.13

func MarshalData(value any, format DataFormat) ([]byte, error)

MarshalData 将结构体序列化为指定格式的数据

func StructToMap

func StructToMap(input any) (map[string]any, error)

StructToMap 将结构体转换为 map[string]any

func UnmarshalData added in v1.0.13

func UnmarshalData[T any](data []byte, format DataFormat) (*T, error)

UnmarshalData 将数据反序列化为指定类型的结构体

Types

type DataFormat

type DataFormat int

DataFormat 是一个自定义类型,用于表示数据格式

const (
	JSON DataFormat = iota
	YAML
	XML
	Gob
)

Jump to

Keyboard shortcuts

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