/
encode_decode.go
236 lines (216 loc) · 8.34 KB
/
encode_decode.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
// Code generated by goa v2.2.4, DO NOT EDIT.
//
// storage gRPC client encoders and decoders
//
// Command:
// $ goa gen goa.design/examples/cellar/design -o
// $(GOPATH)/src/goa.design/examples/cellar
package client
import (
"context"
storagepb "goa.design/examples/cellar/gen/grpc/storage/pb"
storage "goa.design/examples/cellar/gen/storage"
storageviews "goa.design/examples/cellar/gen/storage/views"
goagrpc "goa.design/goa/grpc"
"google.golang.org/grpc"
"google.golang.org/grpc/metadata"
)
// BuildListFunc builds the remote method to invoke for "storage" service
// "list" endpoint.
func BuildListFunc(grpccli storagepb.StorageClient, cliopts ...grpc.CallOption) goagrpc.RemoteFunc {
return func(ctx context.Context, reqpb interface{}, opts ...grpc.CallOption) (interface{}, error) {
for _, opt := range cliopts {
opts = append(opts, opt)
}
if reqpb != nil {
return grpccli.List(ctx, reqpb.(*storagepb.ListRequest), opts...)
}
return grpccli.List(ctx, &storagepb.ListRequest{}, opts...)
}
}
// DecodeListResponse decodes responses from the storage list endpoint.
func DecodeListResponse(ctx context.Context, v interface{}, hdr, trlr metadata.MD) (interface{}, error) {
var view string
{
if vals := hdr.Get("goa-view"); len(vals) > 0 {
view = vals[0]
}
}
message, ok := v.(*storagepb.StoredBottleCollection)
if !ok {
return nil, goagrpc.ErrInvalidType("storage", "list", "*storagepb.StoredBottleCollection", v)
}
res := NewListResult(message)
vres := storageviews.StoredBottleCollection{Projected: res, View: view}
if err := storageviews.ValidateStoredBottleCollection(vres); err != nil {
return nil, err
}
return storage.NewStoredBottleCollection(vres), nil
}
// BuildShowFunc builds the remote method to invoke for "storage" service
// "show" endpoint.
func BuildShowFunc(grpccli storagepb.StorageClient, cliopts ...grpc.CallOption) goagrpc.RemoteFunc {
return func(ctx context.Context, reqpb interface{}, opts ...grpc.CallOption) (interface{}, error) {
for _, opt := range cliopts {
opts = append(opts, opt)
}
if reqpb != nil {
return grpccli.Show(ctx, reqpb.(*storagepb.ShowRequest), opts...)
}
return grpccli.Show(ctx, &storagepb.ShowRequest{}, opts...)
}
}
// EncodeShowRequest encodes requests sent to storage show endpoint.
func EncodeShowRequest(ctx context.Context, v interface{}, md *metadata.MD) (interface{}, error) {
payload, ok := v.(*storage.ShowPayload)
if !ok {
return nil, goagrpc.ErrInvalidType("storage", "show", "*storage.ShowPayload", v)
}
if payload.View != nil {
(*md).Append("view", *payload.View)
}
return NewShowRequest(payload), nil
}
// DecodeShowResponse decodes responses from the storage show endpoint.
func DecodeShowResponse(ctx context.Context, v interface{}, hdr, trlr metadata.MD) (interface{}, error) {
var view string
{
if vals := hdr.Get("goa-view"); len(vals) > 0 {
view = vals[0]
}
}
message, ok := v.(*storagepb.ShowResponse)
if !ok {
return nil, goagrpc.ErrInvalidType("storage", "show", "*storagepb.ShowResponse", v)
}
res := NewShowResult(message)
vres := &storageviews.StoredBottle{Projected: res, View: view}
if err := storageviews.ValidateStoredBottle(vres); err != nil {
return nil, err
}
return storage.NewStoredBottle(vres), nil
}
// BuildAddFunc builds the remote method to invoke for "storage" service "add"
// endpoint.
func BuildAddFunc(grpccli storagepb.StorageClient, cliopts ...grpc.CallOption) goagrpc.RemoteFunc {
return func(ctx context.Context, reqpb interface{}, opts ...grpc.CallOption) (interface{}, error) {
for _, opt := range cliopts {
opts = append(opts, opt)
}
if reqpb != nil {
return grpccli.Add(ctx, reqpb.(*storagepb.AddRequest), opts...)
}
return grpccli.Add(ctx, &storagepb.AddRequest{}, opts...)
}
}
// EncodeAddRequest encodes requests sent to storage add endpoint.
func EncodeAddRequest(ctx context.Context, v interface{}, md *metadata.MD) (interface{}, error) {
payload, ok := v.(*storage.Bottle)
if !ok {
return nil, goagrpc.ErrInvalidType("storage", "add", "*storage.Bottle", v)
}
return NewAddRequest(payload), nil
}
// DecodeAddResponse decodes responses from the storage add endpoint.
func DecodeAddResponse(ctx context.Context, v interface{}, hdr, trlr metadata.MD) (interface{}, error) {
message, ok := v.(*storagepb.AddResponse)
if !ok {
return nil, goagrpc.ErrInvalidType("storage", "add", "*storagepb.AddResponse", v)
}
res := NewAddResult(message)
return res, nil
}
// BuildRemoveFunc builds the remote method to invoke for "storage" service
// "remove" endpoint.
func BuildRemoveFunc(grpccli storagepb.StorageClient, cliopts ...grpc.CallOption) goagrpc.RemoteFunc {
return func(ctx context.Context, reqpb interface{}, opts ...grpc.CallOption) (interface{}, error) {
for _, opt := range cliopts {
opts = append(opts, opt)
}
if reqpb != nil {
return grpccli.Remove(ctx, reqpb.(*storagepb.RemoveRequest), opts...)
}
return grpccli.Remove(ctx, &storagepb.RemoveRequest{}, opts...)
}
}
// EncodeRemoveRequest encodes requests sent to storage remove endpoint.
func EncodeRemoveRequest(ctx context.Context, v interface{}, md *metadata.MD) (interface{}, error) {
payload, ok := v.(*storage.RemovePayload)
if !ok {
return nil, goagrpc.ErrInvalidType("storage", "remove", "*storage.RemovePayload", v)
}
return NewRemoveRequest(payload), nil
}
// BuildRateFunc builds the remote method to invoke for "storage" service
// "rate" endpoint.
func BuildRateFunc(grpccli storagepb.StorageClient, cliopts ...grpc.CallOption) goagrpc.RemoteFunc {
return func(ctx context.Context, reqpb interface{}, opts ...grpc.CallOption) (interface{}, error) {
for _, opt := range cliopts {
opts = append(opts, opt)
}
if reqpb != nil {
return grpccli.Rate(ctx, reqpb.(*storagepb.RateRequest), opts...)
}
return grpccli.Rate(ctx, &storagepb.RateRequest{}, opts...)
}
}
// EncodeRateRequest encodes requests sent to storage rate endpoint.
func EncodeRateRequest(ctx context.Context, v interface{}, md *metadata.MD) (interface{}, error) {
payload, ok := v.(map[uint32][]string)
if !ok {
return nil, goagrpc.ErrInvalidType("storage", "rate", "map[uint32][]string", v)
}
return NewRateRequest(payload), nil
}
// BuildMultiAddFunc builds the remote method to invoke for "storage" service
// "multi_add" endpoint.
func BuildMultiAddFunc(grpccli storagepb.StorageClient, cliopts ...grpc.CallOption) goagrpc.RemoteFunc {
return func(ctx context.Context, reqpb interface{}, opts ...grpc.CallOption) (interface{}, error) {
for _, opt := range cliopts {
opts = append(opts, opt)
}
if reqpb != nil {
return grpccli.MultiAdd(ctx, reqpb.(*storagepb.MultiAddRequest), opts...)
}
return grpccli.MultiAdd(ctx, &storagepb.MultiAddRequest{}, opts...)
}
}
// EncodeMultiAddRequest encodes requests sent to storage multi_add endpoint.
func EncodeMultiAddRequest(ctx context.Context, v interface{}, md *metadata.MD) (interface{}, error) {
payload, ok := v.([]*storage.Bottle)
if !ok {
return nil, goagrpc.ErrInvalidType("storage", "multi_add", "[]*storage.Bottle", v)
}
return NewMultiAddRequest(payload), nil
}
// DecodeMultiAddResponse decodes responses from the storage multi_add endpoint.
func DecodeMultiAddResponse(ctx context.Context, v interface{}, hdr, trlr metadata.MD) (interface{}, error) {
message, ok := v.(*storagepb.MultiAddResponse)
if !ok {
return nil, goagrpc.ErrInvalidType("storage", "multi_add", "*storagepb.MultiAddResponse", v)
}
res := NewMultiAddResult(message)
return res, nil
}
// BuildMultiUpdateFunc builds the remote method to invoke for "storage"
// service "multi_update" endpoint.
func BuildMultiUpdateFunc(grpccli storagepb.StorageClient, cliopts ...grpc.CallOption) goagrpc.RemoteFunc {
return func(ctx context.Context, reqpb interface{}, opts ...grpc.CallOption) (interface{}, error) {
for _, opt := range cliopts {
opts = append(opts, opt)
}
if reqpb != nil {
return grpccli.MultiUpdate(ctx, reqpb.(*storagepb.MultiUpdateRequest), opts...)
}
return grpccli.MultiUpdate(ctx, &storagepb.MultiUpdateRequest{}, opts...)
}
}
// EncodeMultiUpdateRequest encodes requests sent to storage multi_update
// endpoint.
func EncodeMultiUpdateRequest(ctx context.Context, v interface{}, md *metadata.MD) (interface{}, error) {
payload, ok := v.(*storage.MultiUpdatePayload)
if !ok {
return nil, goagrpc.ErrInvalidType("storage", "multi_update", "*storage.MultiUpdatePayload", v)
}
return NewMultiUpdateRequest(payload), nil
}