-
Notifications
You must be signed in to change notification settings - Fork 2
/
information.go
77 lines (65 loc) · 1.11 KB
/
information.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
package types
import (
"fmt"
"math/big"
)
type Field struct {
Name string
Value interface{}
Printer PrintType
}
type PrintType int
var (
EthPrintType PrintType = 1
)
func (f *Field) String() string {
switch f.Printer {
case EthPrintType:
return PrettyETH(f.Value.(*big.Int))
}
switch f.Value.(type) {
case int, uint, int64, int32, int16, int8, uint64, uint32, uint16, uint8:
return fmt.Sprintf("%d", f.Value)
case bool:
return fmt.Sprintf("%v", f.Value)
default:
return fmt.Sprintf("%s", f.Value)
}
}
type Record struct {
Fields []Field
}
func (f *Record) AddField(name string, value interface{}) {
f.Fields = append(f.Fields, Field{
Name: name,
Value: value,
})
}
type Item struct {
Record
Header []Field
}
func NewItem() Item {
return Item{}
}
func (i Item) GetString(s string) string {
for _, f := range i.Fields {
if f.Name == s {
return f.Value.(string)
}
}
return ""
}
func (i Item) GetUint8(s string) uint8 {
for _, f := range i.Fields {
if f.Name == s {
return f.Value.(uint8)
}
}
return 0
}
type Table struct {
Type string
Header []Field
Rows []Record
}