-
Notifications
You must be signed in to change notification settings - Fork 10
/
invoke.go
48 lines (43 loc) · 1.12 KB
/
invoke.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
package ydb
import (
"context"
"github.com/golang/protobuf/proto"
"github.com/yandex-cloud/ydb-go-sdk/v2/internal"
"github.com/ydb-platform/ydb-go-genproto/protos/Ydb"
"google.golang.org/grpc"
)
func invoke(
ctx context.Context, conn *grpc.ClientConn,
resp internal.Response,
method string, req, res proto.Message,
opts ...grpc.CallOption,
) (
err error,
) {
if conn == nil {
return ErrNilConnection
}
err = conn.Invoke(ctx, method, req, resp.GetResponseProto(), opts...)
switch {
case err != nil:
err = mapGRPCError(err)
case !resp.GetOpReady():
err = ErrOperationNotReady
case resp.GetStatus() != Ydb.StatusIds_SUCCESS:
err = &OpError{
Reason: statusCode(resp.GetStatus()),
issues: resp.GetIssues(),
}
}
if err != nil {
return err
}
if res == nil {
// NOTE: YDB API at this moment supports extension of its protocol by
// adding Result structures. That is, one may think that no result is
// provided by some call, but some day it may change and client
// implementation will lag some time – no strict behavior is possible.
return nil
}
return proto.Unmarshal(resp.GetResult().Value, res)
}