Documentation
¶
Overview ¶
Package dynamicstruct ...
Description : dynamicstruct ...
Author : go_developer@163.com<白茶清欢>
Date : 2025-03-23 13:34
Package dynamicstruct ...
Description : dynamicstruct ...
Author : go_developer@163.com<白茶清欢>
Date : 2025-03-23 14:14
Package dynamicstruct ...
Description : dynamicstruct ...
Author : go_developer@163.com<白茶清欢>
Date : 2025-03-23 14:07
Index ¶
Constants ¶
const ( // ArraySplit is the string used to split array elements ArraySplit = "[]" // ArrayRootFlag 传入路径直接以数组开头 ArrayRootFlag = "__RootArrayFlag" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Field ¶
type Field interface { // Name 返回字段名称 Name() string // PointerInt int 指针 PointerInt() *int // Int int Int() int // PointerInt8 int8指针 PointerInt8() *int8 // Int8 int Int8() int8 // PointerInt16 int16指针 PointerInt16() *int16 // Int16 int16 Int16() int16 // PointerInt32 int32指针 PointerInt32() *int32 // Int32 int32 Int32() int32 // PointerInt64 int64指针 PointerInt64() *int64 // Int64 int64 Int64() int64 // PointerUint uint指针 PointerUint() *uint // Uint uint Uint() uint // PointerUint8 uint8指针 PointerUint8() *uint8 // Uint8 uint8 Uint8() uint8 // PointerUint16 uint16指针 PointerUint16() *uint16 // Uint16 uint16 Uint16() uint16 // PointerUint32 uint32指针 PointerUint32() *uint32 // Uint32 uint32 Uint32() uint32 // PointerUint64 uint64指针 PointerUint64() *uint64 // Uint64 uint64 Uint64() uint64 // PointerFloat32 float32指针 PointerFloat32() *float32 // Float32 float32 Float32() float32 // PointerFloat64 float64指针 PointerFloat64() *float64 // Float64 float64 Float64() float64 // PointerString string指针 PointerString() *string // String string String() string // PointerBool bool指针 PointerBool() *bool // Bool bool... Bool() bool // PointerTime time指针 PointerTime() *time.Time // Time time... Time() time.Time // Any any... Any() any }
Field 对结构体字段的操作
type IBuilder ¶
type IBuilder interface { // AddField 添加结构体字段 AddField(name string, pkg string, typ any, tag string, anonymous bool) IBuilder // RemoveField 移除指定名称的结构体字段 RemoveField(name string) IBuilder // HasField 检测指定名称的结构体字段是否存在 HasField(name string) bool // GetField 根据名称获取结构体字段定义 GetField(name string) IFieldConfig // Build 返回动态定义的结构体. Build() IDynamicStruct }
IBuilder 运行时动态生成结构体的接口约束
func ExtendStruct ¶
ExtendStruct 基于已有结构体, 生成动态结构体(相当于继承指定的结构体属性)
type IDynamicStruct ¶
type IDynamicStruct interface { // New 获取结构体实例, 所有字段值均为对应类型的初始零值 New() any // NewSliceOfStructs slice实例化 NewSliceOfStructs() any // NewMapOfStructs map 或者 struct实例化 NewMapOfStructs(key any) any }
IDynamicStruct contains defined dynamic struct. This definition can't be changed anymore, once is built. It provides a method for creating new instances of same defintion.
type IFieldConfig ¶
type IFieldConfig interface { // SetType 设置字段类型. SetType(typ any) IFieldConfig // SetTag 设置字段 tag. SetTag(tag string) IFieldConfig // GetType 获取类型 GetType() any // GetTag 获取tag GetTag() string }
IFieldConfig 结构体字段的定义.
type Reader ¶
type Reader interface { // HasField 是否存在指定名称的字段 HasField(name string) bool // GetField 获取指定字段信息 GetField(name string) Field // GetAllFields 获取全部字段 GetAllFields() []Field // ToStruct 转结构体 ToStruct(value any) error // ToSliceOfReaders 转slice ToSliceOfReaders() []Reader // ToMapReaderOfReaders returns a map of Reader interfaces if value is representation ToMapReaderOfReaders() map[any]Reader // GetValue 获取输入的原始值 GetValue() any }
Reader 通过反射读取结构体信息