OLD | NEW |
1 // Copyright 2016 The LUCI Authors. All rights reserved. | 1 // Copyright 2016 The LUCI Authors. All rights reserved. |
2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
4 | 4 |
5 package main | 5 package main |
6 | 6 |
7 import ( | 7 import ( |
8 "fmt" | 8 "fmt" |
9 "strings" | 9 "strings" |
10 | 10 |
| 11 "github.com/luci/luci-go/common/proto/google/descutil" |
| 12 |
11 "golang.org/x/net/context" | 13 "golang.org/x/net/context" |
12 | 14 |
13 "github.com/luci/luci-go/common/proto/google/descriptor" | |
14 "github.com/luci/luci-go/grpc/discovery" | 15 "github.com/luci/luci-go/grpc/discovery" |
15 "github.com/luci/luci-go/grpc/prpc" | 16 "github.com/luci/luci-go/grpc/prpc" |
| 17 "google.golang.org/genproto/protobuf" |
16 ) | 18 ) |
17 | 19 |
18 type serverDescription struct { | 20 type serverDescription struct { |
19 *discovery.DescribeResponse | 21 *discovery.DescribeResponse |
20 } | 22 } |
21 | 23 |
22 func loadDescription(c context.Context, client *prpc.Client) (*serverDescription
, error) { | 24 func loadDescription(c context.Context, client *prpc.Client) (*serverDescription
, error) { |
23 dc := discovery.NewDiscoveryPRPCClient(client) | 25 dc := discovery.NewDiscoveryPRPCClient(client) |
24 res, err := dc.Describe(c, &discovery.Void{}) | 26 res, err := dc.Describe(c, &discovery.Void{}) |
25 if err != nil { | 27 if err != nil { |
26 return nil, fmt.Errorf("could not load server description: %s",
err) | 28 return nil, fmt.Errorf("could not load server description: %s",
err) |
27 } | 29 } |
28 | 30 |
29 return &serverDescription{res}, nil | 31 return &serverDescription{res}, nil |
30 } | 32 } |
31 | 33 |
32 // resolveInputMessage resolves input message type of a method. | 34 // resolveInputMessage resolves input message type of a method. |
33 func (d *serverDescription) resolveInputMessage(service, method string) (*descri
ptor.DescriptorProto, error) { | 35 func (d *serverDescription) resolveInputMessage(service, method string) (*descri
ptor.DescriptorProto, error) { |
34 » _, obj, _ := d.Description.Resolve(service) | 36 » _, obj, _ := descutil.Resolve(d.Description, service) |
35 serviceDesc, ok := obj.(*descriptor.ServiceDescriptorProto) | 37 serviceDesc, ok := obj.(*descriptor.ServiceDescriptorProto) |
36 if !ok { | 38 if !ok { |
37 return nil, fmt.Errorf("service %q not found", service) | 39 return nil, fmt.Errorf("service %q not found", service) |
38 } | 40 } |
39 | 41 |
40 » mi := serviceDesc.FindMethod(method) | 42 » mi := descutil.FindMethodForService(serviceDesc, method) |
41 if mi == -1 { | 43 if mi == -1 { |
42 return nil, fmt.Errorf("method %q in service %q not found", meth
od, service) | 44 return nil, fmt.Errorf("method %q in service %q not found", meth
od, service) |
43 } | 45 } |
44 | 46 |
45 msgName := serviceDesc.Method[mi].GetInputType() | 47 msgName := serviceDesc.Method[mi].GetInputType() |
46 msgName = strings.TrimPrefix(msgName, ".") | 48 msgName = strings.TrimPrefix(msgName, ".") |
47 return d.resolveMessage(msgName) | 49 return d.resolveMessage(msgName) |
48 } | 50 } |
49 | 51 |
50 func (d *serverDescription) resolveMessage(name string) (*descriptor.DescriptorP
roto, error) { | 52 func (d *serverDescription) resolveMessage(name string) (*descriptor.DescriptorP
roto, error) { |
51 » _, obj, _ := d.Description.Resolve(name) | 53 » _, obj, _ := descutil.Resolve(d.Description, name) |
52 msg, ok := obj.(*descriptor.DescriptorProto) | 54 msg, ok := obj.(*descriptor.DescriptorProto) |
53 if !ok { | 55 if !ok { |
54 return nil, fmt.Errorf("message %q not found", name) | 56 return nil, fmt.Errorf("message %q not found", name) |
55 } | 57 } |
56 return msg, nil | 58 return msg, nil |
57 } | 59 } |
OLD | NEW |