treflect

package
v1.0.54 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContainTag added in v1.0.11

func ContainTag(item interface{}, tag string) bool

ContainTag 判断结构体是否含有特定的json内容

func ConvertAnyMapToStruct added in v1.0.45

func ConvertAnyMapToStruct[T any](anyMap map[string]any) (*T, error)

ConvertAnyMapToStruct 把任意map转换为目标结构体

func Copy

func Copy(src interface{}) interface{}

Copy creates a deep copy of whatever is passed to it and returns the copy in an interface{}. The returned value will need to be asserted to the correct type. note: can't copy unexported field: https://stackoverflow.com/questions/38369350/how-to-clone-a-structure-with-unexported-field

func DeepCopySlice added in v1.0.23

func DeepCopySlice[T any](data []T, ns ...int) []T

DeepCopySlice 深度复制切片

func GetAllFields added in v1.0.37

func GetAllFields(item interface{}) ([]*reflect.StructField, error)

GetAllFields 取出全部Field字段

func GetAnyMapValue added in v1.0.45

func GetAnyMapValue[T any](anyMap map[string]any, key string, defaultValue T) T

GetAnyMapValue 从Map中取出对应值

func GetFieldSpecificValue added in v1.0.37

func GetFieldSpecificValue[T any](item interface{}, fieldName string) (T, reflect.Kind, error)

GetFieldSpecificValue 取出Struct的Field值, 传入精确的类型

func GetFieldTag added in v1.0.37

func GetFieldTag(field *reflect.StructField, tagType string) (string, bool)

GetFieldTag 获取StructField对应的tag值

func GetFieldValue

func GetFieldValue(item interface{}, fieldName string) (reflect.Value, error)

func GetFieldValueToFloat added in v1.0.37

func GetFieldValueToFloat(item interface{}, fieldName string) (float64, error)

func GetFieldValueToInt added in v1.0.37

func GetFieldValueToInt(item interface{}, fieldName string) (int64, error)

func SetField

func SetField(item interface{}, fieldName string, value interface{}) error

SetField 修改结构体字段的值

func StructToAnyMap added in v1.0.44

func StructToAnyMap(item interface{}, skip ...string) map[string]interface{}

StructToAnyMap 把任意结构体转换为字符串形式的任意map

func StructToAnyMapDeep added in v1.0.44

func StructToAnyMapDeep(item interface{}, skip ...string) map[string]interface{}

StructToAnyMapDeep 把任意结构体数据递归转换为字符串形式的任意map

func StructToAnyMapWithJson added in v1.0.44

func StructToAnyMapWithJson(item interface{}, skip ...string) map[string]interface{}

StructToAnyMapWithJson 把结构体转换为json字符串形式的任意map

func StructToAnyMapWithJsonDeep added in v1.0.44

func StructToAnyMapWithJsonDeep(item interface{}, skip ...string) map[string]interface{}

StructToAnyMapWithJsonDeep 把任意结构体数据递归转换为json字符串形式的任意map

func ToAnyMap added in v1.0.9

func ToAnyMap(item interface{}, skip ...string) map[string]interface{}

func VerifyField added in v1.0.48

func VerifyField(item interface{}, fieldNames []string) error

Types

type Interface

type Interface interface {
	DeepCopy() interface{}
}

Interface for delegating copy process to type

Jump to

Keyboard shortcuts

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