/
remoteclient.go
53 lines (45 loc) · 1.51 KB
/
remoteclient.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
package chat
import (
"time"
"github.com/adamwalz/keybase-client/go/chat/globals"
"github.com/adamwalz/keybase-client/go/chat/types"
"github.com/adamwalz/keybase-client/go/chat/utils"
"github.com/keybase/go-framed-msgpack-rpc/rpc"
"golang.org/x/net/context"
)
type RemoteClient struct {
utils.DebugLabeler
cli rpc.GenericClient
}
func NewRemoteClient(g *globals.Context, cli rpc.GenericClient) *RemoteClient {
return &RemoteClient{
DebugLabeler: utils.NewDebugLabeler(g.ExternalG(), "RemoteClient", false),
cli: cli,
}
}
func (c *RemoteClient) Call(ctx context.Context, method string, arg interface{},
res interface{}, timeout time.Duration) (err error) {
defer c.Trace(ctx, &err, method)()
err = c.cli.Call(ctx, method, arg, res, timeout)
if err == nil {
if rlRes, ok := res.(types.RateLimitedResult); ok {
globals.CtxAddRateLimit(ctx, rlRes.GetRateLimit())
}
}
return err
}
func (c *RemoteClient) CallCompressed(ctx context.Context, method string, arg interface{},
res interface{}, ctype rpc.CompressionType, timeout time.Duration) (err error) {
defer c.Trace(ctx, &err, method)()
err = c.cli.CallCompressed(ctx, method, arg, res, ctype, timeout)
if err == nil {
if rlRes, ok := res.(types.RateLimitedResult); ok {
globals.CtxAddRateLimit(ctx, rlRes.GetRateLimit())
}
}
return err
}
func (c *RemoteClient) Notify(ctx context.Context, method string, arg interface{}, timeout time.Duration) (err error) {
defer c.Trace(ctx, &err, method)()
return c.cli.Notify(ctx, method, arg, timeout)
}