Documentation
¶
Index ¶
- func Clone(src interface{}) (interface{}, error)
- func Compare(a, b interface{}) (bool, error)
- func Convert(src interface{}, dstType reflect.Type) (interface{}, error)
- func DeepClone(src interface{}) (interface{}, error)
- func DeepCompare(a, b interface{}) bool
- func Deserialize(data []byte, obj interface{}) error
- func FilterFields(obj interface{}, condition func(fieldName string, fieldValue interface{}) bool) map[string]interface{}
- func FromMap(obj interface{}, data map[string]interface{}) error
- func GetField(obj interface{}, field string) (interface{}, error)
- func GetFieldNames(obj interface{}) ([]string, error)
- func IsEqual(a, b interface{}) bool
- func IsNil(obj interface{}) bool
- func Merge(a, b map[string]interface{}) map[string]interface{}
- func MergeAndOverride(a, b map[string]interface{}) map[string]interface{}
- func Serialize(obj interface{}) ([]byte, error)
- func SetField(obj interface{}, field string, value interface{}) error
- func SetFields(obj interface{}, fields map[string]interface{}) error
- func ToMap(obj interface{}) (map[string]interface{}, error)
- func TypeOf(obj interface{}) string
- func Validate(obj interface{}) error
- type BaseObject
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 ¶
Compare 比较两个结构体的字段 Compare compares two structs field by field. 参数:
a: 第一个结构体,必须是指针。 b: 第二个结构体,必须是指针。
返回值:
如果相等返回 true,否则返回 false,可能的错误信息。
func Convert ¶
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 ¶
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 ¶
FromMap 从映射中填充结构体 FromMap populates a struct from a map. 参数:
obj: 目标对象,必须是非空指针。 data: 包含字段名和对应值的映射。
返回值:
可能的错误信息。
func GetField ¶
GetField 获取结构体字段的值 GetField retrieves the value of a field from a struct. 参数:
obj: 目标对象,必须是非空指针。 field: 字段名称。
返回值:
返回字段的值和可能的错误信息。
func GetFieldNames ¶
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 ¶
Merge 合并两个映射 Merge merges two maps of string keys and interface values. 参数:
a: 第一个映射。 b: 第二个映射。
返回值:
返回合并后的映射。
func MergeAndOverride ¶
MergeAndOverride 合并两个映射,后者覆盖前者 MergeAndOverride merges two maps, with the second map overriding the first in case of key conflicts. 参数:
a: 第一个映射。 b: 第二个映射。
返回值:
返回合并后的映射。
func Serialize ¶
Serialize 将对象转换为 JSON Serialize converts an object to JSON. 参数:
obj: 需要序列化的对象。
返回值:
JSON 字节数组和可能的错误信息。
func SetField ¶
SetField 设置结构体字段的值 SetField sets the value of a field in a struct. 参数:
obj: 目标对象,必须是非空指针。 field: 字段名称。 value: 要设置的值。
返回值:
可能的错误信息。
func SetFields ¶
SetFields 设置结构体多个字段的值 SetFields sets the values of multiple fields in a struct. 参数:
obj: 目标对象,必须是非空指针。 fields: 包含字段名和对应值的映射。
返回值:
可能的错误信息。
func ToMap ¶
ToMap 将结构体转换为映射 ToMap converts a struct to a map. 参数:
obj: 目标对象,必须是非空指针。
返回值:
返回映射和可能的错误信息。
Types ¶
type BaseObject ¶
type BaseObject interface {
GetID() interface{} // 获取对象的ID
}
BaseObject 定义基础对象接口 BaseObject defines a base object interface.