整理代码结构, 增加普通结构体单元测试
This commit is contained in:
44
abstract.go
Normal file
44
abstract.go
Normal file
@ -0,0 +1,44 @@
|
||||
// Package dynamicstruct ...
|
||||
//
|
||||
// Description : dynamicstruct ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 2025-03-23 13:34
|
||||
package dynamicstruct
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
// IFieldConfig 结构体字段的定义.
|
||||
type IFieldConfig interface {
|
||||
// SetType 设置字段类型.
|
||||
SetType(typ any) IFieldConfig
|
||||
// SetTag 设置字段 tag.
|
||||
SetTag(tag string) IFieldConfig
|
||||
}
|
||||
|
||||
// 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 IDynamicStruct interface {
|
||||
// New 获取结构体实例, 所有字段值均为对应类型的初始零值
|
||||
New() any
|
||||
|
||||
// NewSliceOfStructs slice实例化
|
||||
NewSliceOfStructs() any
|
||||
|
||||
// NewMapOfStructs map 或者 struct实例化
|
||||
NewMapOfStructs(key any) any
|
||||
}
|
Reference in New Issue
Block a user