objectutil

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clone

func Clone(src interface{}) (interface{}, error)

Clone 直接克隆对象 Clone creates a direct clone of the provided object. 参数:

src: 需要克隆的对象,必须是非空指针。

返回值:

返回克隆后的对象和可能的错误信息。

func Compare

func Compare(a, b interface{}) (bool, error)

Compare 比较两个结构体的字段 Compare compares two structs field by field. 参数:

a: 第一个结构体,必须是指针。
b: 第二个结构体,必须是指针。

返回值:

如果相等返回 true,否则返回 false,可能的错误信息。

func Convert

func Convert(src interface{}, dstType reflect.Type) (interface{}, error)

Convert 转换对象类型 Convert converts an object of one type to another. 参数:

src: 源对象。
dstType: 目标对象类型。

返回值:

返回转换后的对象和可能的错误信息。

func DeepClone

func DeepClone(src interface{}) (interface{}, error)

DeepClone 执行深度复制 DeepClone performs a deep copy of the provided object. 参数:

src: 需要被复制的对象,必须是非空指针。

返回值:

返回复制后的对象和可能的错误信息。

func DeepCompare

func DeepCompare(a, b interface{}) bool

DeepCompare 执行深度比较 DeepCompare performs a deep comparison of two objects. 参数:

a: 第一个对象。
b: 第二个对象。

返回值:

如果相等返回 true,否则返回 false。

func Deserialize

func Deserialize(data []byte, obj interface{}) error

Deserialize 将 JSON 数据转换为对象 Deserialize converts JSON data to an object. 参数:

data: JSON 字节数组。
obj: 目标对象,必须是非空指针。

返回值:

可能的错误信息。

func FilterFields

func FilterFields(obj interface{}, condition func(fieldName string, fieldValue interface{}) bool) map[string]interface{}

FilterFields 过滤结构体的字段 FilterFields filters the fields of a struct based on a given condition function. 参数:

obj: 目标对象,必须是非空指针。
condition: 条件函数,接受字段名和字段值,返回是否满足条件。

返回值:

返回满足条件的字段名和对应值的映射。

func FromMap

func FromMap(obj interface{}, data map[string]interface{}) error

FromMap 从映射中填充结构体 FromMap populates a struct from a map. 参数:

obj: 目标对象,必须是非空指针。
data: 包含字段名和对应值的映射。

返回值:

可能的错误信息。

func GetField

func GetField(obj interface{}, field string) (interface{}, error)

GetField 获取结构体字段的值 GetField retrieves the value of a field from a struct. 参数:

obj: 目标对象,必须是非空指针。
field: 字段名称。

返回值:

返回字段的值和可能的错误信息。

func GetFieldNames

func GetFieldNames(obj interface{}) ([]string, error)

GetFieldNames 获取结构体字段名称 GetFieldNames retrieves the field names of a struct. 参数:

obj: 目标对象,必须是非空指针。

返回值:

返回字段名称的切片和可能的错误信息。

func IsEqual

func IsEqual(a, b interface{}) bool

IsEqual 检查两个对象是否相等 IsEqual checks if two objects are equal. 参数:

a: 第一个对象。
b: 第二个对象。

返回值:

如果相等返回 true,否则返回 false。

func IsNil

func IsNil(obj interface{}) bool

IsNil 检查对象是否为 nil IsNil checks if an interface is nil. 参数:

obj: 目标对象。

返回值:

如果为 nil 返回 true,否则返回 false。

func Merge

func Merge(a, b map[string]interface{}) map[string]interface{}

Merge 合并两个映射 Merge merges two maps of string keys and interface values. 参数:

a: 第一个映射。
b: 第二个映射。

返回值:

返回合并后的映射。

func MergeAndOverride

func MergeAndOverride(a, b map[string]interface{}) map[string]interface{}

MergeAndOverride 合并两个映射,后者覆盖前者 MergeAndOverride merges two maps, with the second map overriding the first in case of key conflicts. 参数:

a: 第一个映射。
b: 第二个映射。

返回值:

返回合并后的映射。

func Serialize

func Serialize(obj interface{}) ([]byte, error)

Serialize 将对象转换为 JSON Serialize converts an object to JSON. 参数:

obj: 需要序列化的对象。

返回值:

JSON 字节数组和可能的错误信息。

func SetField

func SetField(obj interface{}, field string, value interface{}) error

SetField 设置结构体字段的值 SetField sets the value of a field in a struct. 参数:

obj: 目标对象,必须是非空指针。
field: 字段名称。
value: 要设置的值。

返回值:

可能的错误信息。

func SetFields

func SetFields(obj interface{}, fields map[string]interface{}) error

SetFields 设置结构体多个字段的值 SetFields sets the values of multiple fields in a struct. 参数:

obj: 目标对象,必须是非空指针。
fields: 包含字段名和对应值的映射。

返回值:

可能的错误信息。

func ToMap

func ToMap(obj interface{}) (map[string]interface{}, error)

ToMap 将结构体转换为映射 ToMap converts a struct to a map. 参数:

obj: 目标对象,必须是非空指针。

返回值:

返回映射和可能的错误信息。

func TypeOf

func TypeOf(obj interface{}) string

TypeOf 返回对象的类型 TypeOf returns the type of an object. 参数:

obj: 目标对象。

返回值:

对象的类型字符串。

func Validate

func Validate(obj interface{}) error

Validate 验证对象是否实现了 BaseObject 接口 Validate checks if the object satisfies the BaseObject interface. 参数:

obj: 目标对象。

返回值:

可能的错误信息。

Types

type BaseObject

type BaseObject interface {
	GetID() interface{} // 获取对象的ID
}

BaseObject 定义基础对象接口 BaseObject defines a base object interface.

Jump to

Keyboard shortcuts

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