forked from davyxu/tabtoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
struct.go
56 lines (38 loc) · 1.03 KB
/
struct.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
package bindata
import (
"github.com/adamluo159/tabtoy/v3/model"
)
// 写入表的一行
func writeStruct(globals *model.Globals, tab *model.DataTable, row int) (*BinaryWriter, error) {
structWriter := NewBinaryWriter()
// 一个结构体
for _, header := range tab.Headers {
if header == nil {
continue
}
if globals.CanDoAction(model.ActionNoGenFieldBinary, header) {
continue
}
cell := tab.GetCell(row, header.Cell.Col)
if cell == nil {
continue
}
goType := model.LanguagePrimitive(header.TypeInfo.FieldType, "go")
// 写入字段
if header.TypeInfo.IsArray() {
for _, elementValue := range cell.ValueList {
if err := writePair(globals, structWriter, header.TypeInfo, goType, elementValue, header.Cell.Col); err != nil {
return nil, err
}
}
} else {
// 空格不输出
if cell.Value != "" {
if err := writePair(globals, structWriter, header.TypeInfo, goType, cell.Value, header.Cell.Col); err != nil {
return nil, err
}
}
}
}
return structWriter, nil
}