-
Notifications
You must be signed in to change notification settings - Fork 10
/
wrap.go
75 lines (65 loc) · 1.7 KB
/
wrap.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
package internal
import (
"github.com/golang/protobuf/proto"
"github.com/ydb-platform/ydb-go-genproto/protos/Ydb"
"github.com/ydb-platform/ydb-go-genproto/protos/Ydb_Issue"
)
type Operation struct {
method string
req proto.Message
res proto.Message
resp Response
}
func WrapWithResponse(method string, req proto.Message, resp Response) Operation {
return Operation{
method: method,
req: req,
resp: resp,
}
}
func Wrap(method string, req, res proto.Message) Operation {
return Operation{
method: method,
req: req,
res: res,
}
}
func Unwrap(op Operation) (method string, req, res proto.Message, resp Response) {
return op.method, op.req, op.res, op.resp
}
// StreamOperationResponse is an interface that provides access to the
// API-specific response fields.
//
// NOTE: YDB API currently does not provide generic response wrapper as it does
// with RPC API. Thus wee need to generalize it by the hand using this interface.
//
// This generalization is needed for checking status codes and issues in one place.
type StreamOperationResponse interface {
GetStatus() Ydb.StatusIds_StatusCode
GetIssues() []*Ydb_Issue.IssueMessage
}
type StreamOperation struct {
method string
req proto.Message
resp StreamOperationResponse
processor func(error)
}
func WrapStreamOperation(
method string, req proto.Message,
resp StreamOperationResponse,
p func(error),
) StreamOperation {
return StreamOperation{
method: method,
req: req,
resp: resp,
processor: p,
}
}
func UnwrapStreamOperation(op StreamOperation) (
method string, req proto.Message,
resp StreamOperationResponse,
processor func(error),
) {
return op.method, op.req, op.resp, op.processor
}