/
types.go
102 lines (86 loc) · 1.78 KB
/
types.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package parser
import "fmt"
type Type struct {
Name string
KeyType *Type // Maybe map
ValueType *Type // Maybe map, list, or set
Annotations []*Annotation
}
type Typedef struct {
*Type
Alias string
Annotations []*Annotation
}
type EnumValue struct {
Name string
Value int
Annotations []*Annotation
}
type Enum struct {
Name string
Values map[string]*EnumValue
Annotations []*Annotation
}
type Constant struct {
Name string
Type *Type
Value interface{}
}
type Field struct {
ID int
Name string
Optional bool
Type *Type
Default interface{}
Annotations []*Annotation
}
type Struct struct {
Name string
Fields []*Field
Annotations []*Annotation
}
type Method struct {
Comment string
Name string
Oneway bool
ReturnType *Type
Arguments []*Field
Exceptions []*Field
Annotations []*Annotation
}
type Service struct {
Name string
Extends string
Methods map[string]*Method
Annotations []*Annotation
}
type Thrift struct {
Includes map[string]string // name -> unique identifier
Typedefs map[string]*Typedef
Namespaces map[string]string
Constants map[string]*Constant
Enums map[string]*Enum
Structs map[string]*Struct
Exceptions map[string]*Struct
Unions map[string]*Struct
Services map[string]*Service
}
type Identifier string
type KeyValue struct {
Key, Value interface{}
}
type Annotation struct {
Name string
Value string
}
func (t *Type) String() string {
switch t.Name {
case "map":
return fmt.Sprintf("map<%s,%s>", t.KeyType.String(), t.ValueType.String())
case "list":
return fmt.Sprintf("list<%s>", t.ValueType.String())
case "set":
return fmt.Sprintf("set<%s>", t.ValueType.String())
}
return t.Name
}