-
Notifications
You must be signed in to change notification settings - Fork 2
/
service.go
32 lines (26 loc) · 891 Bytes
/
service.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
package proto_reader
import "github.com/emicklei/proto"
func parseServices(result *ParseResult, definition *ProtobufDefinition) {
methods := parseMethods(result, definition)
definition.Services = make(map[string]*Service)
for _, s := range result.Services {
var service Service
service.Name = s.Name
service.Comment = trimComment(s.Comment)
service.Methods = make(map[string]*Method)
for _, elem := range s.Elements {
linkMethods(elem, methods, service.Methods)
}
optKey := encodeOptionKey(serviceKey, service.Name)
options := parseOptions(result.Options[optKey])
service.Options = options
definition.Services[service.Name] = &service
}
}
func linkMethods(element proto.Visitee, input map[string]*Method, output map[string]*Method) {
switch element.(type) {
case *proto.RPC:
casted := element.(*proto.RPC)
output[casted.Name] = input[casted.Name]
}
}