-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtypes.go
89 lines (71 loc) · 2.25 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
package protostub
import (
"fmt"
"strings"
)
// This contains the types that the in-memory representation of the protobuf
// will be built out of. Some have associated visitors that will generate them,
// while others are just components
// ProtoType defines that a type must have both a name and a TypeName
type ProtoType interface {
Name() string
Typename() string
}
// Member is a member of a message
type Member struct {
name string
typename string
Comment []string
}
// Function is a function, usually a RPC method in this case
type Function struct {
name string
returnType string
parameters []string
Comment []string
}
// Message represents a ProtoBuf message
type Message struct {
name string
Types []ProtoType
Members []Member
IsExtend bool
Comment []string
}
// Service representts a protobuf service
type Service struct {
name string
Types []ProtoType
Functions []Function
Comment []string
}
// Enum is a protobuf enum
type Enum struct {
name string
Members []Member
}
// Name returns the name of the member
func (m Member) Name() string { return m.name }
// Typename returns the type name of the member
func (m Member) Typename() string { return m.typename }
// Name returns the name of the message
func (m Message) Name() string { return m.name }
// Typename returns the type name of the message. Note that in this case,
// Name() == Typename()
func (m Message) Typename() string { return m.name }
// Name returns the name of the service
func (s Service) Name() string { return s.name }
// Typename returns the typename of the service. Like Message, in this case
// Typename is the same as Name.
func (s Service) Typename() string { return s.name }
// Name returns the name of the enum.
func (s Enum) Name() string { return s.name }
// Typename returns the typename of the enum. Again, it is the same as Name.
func (s Enum) Typename() string { return s.name }
// Name returns the name of the function.
func (f Function) Name() string { return f.name }
// Typename returns the typename of the function. This includes the name,
// parameter, and return value in the form foo(bar) -> baz.
func (f Function) Typename() string {
return fmt.Sprintf("%s(%s) -> %s", f.name, strings.Join(f.parameters, ", "), f.returnType)
}