forked from gin-admin/gin-admin-cli
/
tpl.go
78 lines (73 loc) · 2.11 KB
/
tpl.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package generate
// TplItem 模板项
type TplItem struct {
StructName string `json:"struct_name"` // 结构体名称
Comment string `json:"comment"` // 注释
Fields []TplFieldItem `json:"fields"` // 字段项
}
func (t TplItem) toSchemaFields() []schemaField {
var items []schemaField
for _, f := range t.Fields {
items = append(items, schemaField{
Name: f.StructFieldName,
Comment: f.Comment,
Type: f.StructFieldType,
IsRequired: f.StructFieldRequired,
})
}
return items
}
func (t TplItem) toEntityFields() []entityField {
var items []entityField
for _, f := range t.Fields {
items = append(items, entityField{
Name: f.StructFieldName,
Comment: f.Comment,
Type: f.StructFieldType,
GormOptions: f.GormOptions,
})
}
return items
}
// TplFieldItem 模板字段项
type TplFieldItem struct {
StructFieldName string `json:"struct_field_name"` // 结构体字段名称
StructFieldRequired bool `json:"struct_field_required"` // 结构字段必选项
Comment string `json:"comment"` // 注释
StructFieldType string `json:"struct_field_type"` // 结构体字段类型
GormOptions string `json:"gorm_options"` // gorm配置项
}
// {
// "struct_name": "Task",
// "comment": "任务管理",
// "fields": [
// {
// "struct_field_name": "RecordID",
// "comment": "记录ID",
// "struct_field_required": false,
// "struct_field_type": "string",
// "gorm_options": "size:36;index;"
// },
// {
// "struct_field_name": "Name",
// "comment": "任务名称",
// "struct_field_required": true,
// "struct_field_type": "string",
// "gorm_options": "size:50;index;"
// },
// {
// "struct_field_name": "Memo",
// "comment": "备注",
// "struct_field_required": false,
// "struct_field_type": "string",
// "gorm_options": "size:500;"
// },
// {
// "struct_field_name": "Creator",
// "comment": "创建者",
// "struct_field_required": false,
// "struct_field_type": "string",
// "gorm_options": "size:36;index;"
// }
// ]
// }