-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtable.go
57 lines (47 loc) · 799 Bytes
/
table.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
package table
type Table struct {
Header Header
Rows []Row
}
type Header struct {
Text string
Cells []HeaderCell
}
type HeaderCell struct {
Key string
Index int
}
type Row struct {
Text string
Cells []RowCell
}
type RowCell struct {
Value string
Relation string
}
func (t *Table) Row(index int) *Row {
if len(t.Rows) > index {
return &t.Rows[index]
}
return nil
}
func (h *Header) append(cell HeaderCell) {
h.Cells = append(h.Cells, cell)
}
func (r *Row) append(cell RowCell) {
r.Cells = append(r.Cells, cell)
}
func (r *Row) Cell(index int) *RowCell {
if len(r.Cells) > index {
return &r.Cells[index]
}
return nil
}
func (r *Row) CellByName(s string) *RowCell {
for _, cell := range r.Cells {
if cell.Relation == s {
return &cell
}
}
return nil
}