-
Notifications
You must be signed in to change notification settings - Fork 164
/
src.go
112 lines (100 loc) · 2.31 KB
/
src.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
103
104
105
106
107
108
109
110
111
112
package parser
// File represents a go source file.
type File struct {
Comment string
Package string
// Only used to get the middleware type
FuncType FuncType
Imports []NamedTypeValue
Constants []NamedTypeValue
Vars []NamedTypeValue
Interfaces []Interface
Structures []Struct
Methods []Method
}
// Struct stores go struct information.
type Struct struct {
Name string
Comment string
Vars []NamedTypeValue
}
// FuncType is used to store e.x (type Middleware func(a)a) types
type FuncType struct {
Name string
Parameters []NamedTypeValue
Results []NamedTypeValue
}
// Interface stores go interface information.
type Interface struct {
Name string
Comment string
Methods []Method
}
// Method stores go method information.
type Method struct {
Comment string
Name string
Struct NamedTypeValue
Body string
Parameters []NamedTypeValue
Results []NamedTypeValue
}
// NamedTypeValue is used to store any type of name type = value ( e.x var a = 2)
type NamedTypeValue struct {
Name string
Type string
Value string
}
// NewNameType create a NamedTypeValue without a value.
func NewNameType(name string, tp string) NamedTypeValue {
return NamedTypeValue{
Name: name,
Type: tp,
}
}
// NewNameTypeValue create a NamedTypeValue with a value.
func NewNameTypeValue(name string, tp string, vl string) NamedTypeValue {
return NamedTypeValue{
Name: name,
Type: tp,
Value: vl,
}
}
// NewMethod creates a new method.
func NewMethod(name string, str NamedTypeValue, body string, parameters, results []NamedTypeValue) Method {
return Method{
Name: name,
Comment: "",
Struct: str,
Body: body,
Parameters: parameters,
Results: results,
}
}
// NewInterface creates a new interface.
func NewInterface(name string, methods []Method) Interface {
return Interface{
Name: name,
Comment: "",
Methods: methods,
}
}
// NewStruct creates a new struct.
func NewStruct(name string, vars []NamedTypeValue) Struct {
return Struct{
Name: name,
Comment: "",
Vars: vars,
}
}
// NewFile creates a new empty file.
func NewFile() File {
return File{
Interfaces: []Interface{},
Imports: []NamedTypeValue{},
Structures: []Struct{},
Vars: []NamedTypeValue{},
Constants: []NamedTypeValue{},
Methods: []Method{},
}
}