forked from jaegertracing/jaeger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tchan-driver.go
101 lines (79 loc) · 2.54 KB
/
tchan-driver.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
// @generated Code generated by thrift-gen. Do not modify.
// Package driver is generated code used to make or handle TChannel calls using Thrift.
package driver
import (
"fmt"
athrift "github.com/apache/thrift/lib/go/thrift"
"github.com/uber/tchannel-go/thrift"
)
// Interfaces for the service and client for the services defined in the IDL.
// TChanDriver is the interface that defines the server handler and client interface.
type TChanDriver interface {
FindNearest(ctx thrift.Context, location string) ([]*DriverLocation, error)
}
// Implementation of a client and service handler.
type tchanDriverClient struct {
thriftService string
client thrift.TChanClient
}
func NewTChanDriverInheritedClient(thriftService string, client thrift.TChanClient) *tchanDriverClient {
return &tchanDriverClient{
thriftService,
client,
}
}
// NewTChanDriverClient creates a client that can be used to make remote calls.
func NewTChanDriverClient(client thrift.TChanClient) TChanDriver {
return NewTChanDriverInheritedClient("Driver", client)
}
func (c *tchanDriverClient) FindNearest(ctx thrift.Context, location string) ([]*DriverLocation, error) {
var resp DriverFindNearestResult
args := DriverFindNearestArgs{
Location: location,
}
success, err := c.client.Call(ctx, c.thriftService, "findNearest", &args, &resp)
if err == nil && !success {
}
return resp.GetSuccess(), err
}
type tchanDriverServer struct {
handler TChanDriver
}
// NewTChanDriverServer wraps a handler for TChanDriver so it can be
// registered with a thrift.Server.
func NewTChanDriverServer(handler TChanDriver) thrift.TChanServer {
return &tchanDriverServer{
handler,
}
}
func (s *tchanDriverServer) Service() string {
return "Driver"
}
func (s *tchanDriverServer) Methods() []string {
return []string{
"findNearest",
}
}
func (s *tchanDriverServer) Handle(ctx thrift.Context, methodName string, protocol athrift.TProtocol) (bool, athrift.TStruct, error) {
switch methodName {
case "findNearest":
return s.handleFindNearest(ctx, protocol)
default:
return false, nil, fmt.Errorf("method %v not found in service %v", methodName, s.Service())
}
}
func (s *tchanDriverServer) handleFindNearest(ctx thrift.Context, protocol athrift.TProtocol) (bool, athrift.TStruct, error) {
var req DriverFindNearestArgs
var res DriverFindNearestResult
if err := req.Read(protocol); err != nil {
return false, nil, err
}
r, err :=
s.handler.FindNearest(ctx, req.Location)
if err != nil {
return false, nil, err
} else {
res.Success = r
}
return err == nil, &res, nil
}