/
encode_decode.go
226 lines (205 loc) · 7.49 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
// Code generated by goa v3.16.1, DO NOT EDIT.
//
// chatter gRPC client encoders and decoders
//
// Command:
// $ goa gen goa.design/examples/streaming/design
package client
import (
"context"
chatter "goa.design/examples/streaming/gen/chatter"
chatterpb "goa.design/examples/streaming/gen/grpc/chatter/pb"
goagrpc "goa.design/goa/v3/grpc"
"google.golang.org/grpc"
"google.golang.org/grpc/metadata"
)
// BuildLoginFunc builds the remote method to invoke for "chatter" service
// "login" endpoint.
func BuildLoginFunc(grpccli chatterpb.ChatterClient, cliopts ...grpc.CallOption) goagrpc.RemoteFunc {
return func(ctx context.Context, reqpb any, opts ...grpc.CallOption) (any, error) {
for _, opt := range cliopts {
opts = append(opts, opt)
}
if reqpb != nil {
return grpccli.Login(ctx, reqpb.(*chatterpb.LoginRequest), opts...)
}
return grpccli.Login(ctx, &chatterpb.LoginRequest{}, opts...)
}
}
// EncodeLoginRequest encodes requests sent to chatter login endpoint.
func EncodeLoginRequest(ctx context.Context, v any, md *metadata.MD) (any, error) {
payload, ok := v.(*chatter.LoginPayload)
if !ok {
return nil, goagrpc.ErrInvalidType("chatter", "login", "*chatter.LoginPayload", v)
}
(*md).Append("user", payload.User)
(*md).Append("password", payload.Password)
return NewProtoLoginRequest(), nil
}
// DecodeLoginResponse decodes responses from the chatter login endpoint.
func DecodeLoginResponse(ctx context.Context, v any, hdr, trlr metadata.MD) (any, error) {
message, ok := v.(*chatterpb.LoginResponse)
if !ok {
return nil, goagrpc.ErrInvalidType("chatter", "login", "*chatterpb.LoginResponse", v)
}
res := NewLoginResult(message)
return res, nil
}
// BuildEchoerFunc builds the remote method to invoke for "chatter" service
// "echoer" endpoint.
func BuildEchoerFunc(grpccli chatterpb.ChatterClient, cliopts ...grpc.CallOption) goagrpc.RemoteFunc {
return func(ctx context.Context, reqpb any, opts ...grpc.CallOption) (any, error) {
for _, opt := range cliopts {
opts = append(opts, opt)
}
if reqpb != nil {
return grpccli.Echoer(ctx, opts...)
}
return grpccli.Echoer(ctx, opts...)
}
}
// EncodeEchoerRequest encodes requests sent to chatter echoer endpoint.
func EncodeEchoerRequest(ctx context.Context, v any, md *metadata.MD) (any, error) {
payload, ok := v.(*chatter.EchoerPayload)
if !ok {
return nil, goagrpc.ErrInvalidType("chatter", "echoer", "*chatter.EchoerPayload", v)
}
(*md).Append("authorization", payload.Token)
return nil, nil
}
// DecodeEchoerResponse decodes responses from the chatter echoer endpoint.
func DecodeEchoerResponse(ctx context.Context, v any, hdr, trlr metadata.MD) (any, error) {
return &EchoerClientStream{
stream: v.(chatterpb.Chatter_EchoerClient),
}, nil
}
// BuildListenerFunc builds the remote method to invoke for "chatter" service
// "listener" endpoint.
func BuildListenerFunc(grpccli chatterpb.ChatterClient, cliopts ...grpc.CallOption) goagrpc.RemoteFunc {
return func(ctx context.Context, reqpb any, opts ...grpc.CallOption) (any, error) {
for _, opt := range cliopts {
opts = append(opts, opt)
}
if reqpb != nil {
return grpccli.Listener(ctx, opts...)
}
return grpccli.Listener(ctx, opts...)
}
}
// EncodeListenerRequest encodes requests sent to chatter listener endpoint.
func EncodeListenerRequest(ctx context.Context, v any, md *metadata.MD) (any, error) {
payload, ok := v.(*chatter.ListenerPayload)
if !ok {
return nil, goagrpc.ErrInvalidType("chatter", "listener", "*chatter.ListenerPayload", v)
}
(*md).Append("authorization", payload.Token)
return nil, nil
}
// DecodeListenerResponse decodes responses from the chatter listener endpoint.
func DecodeListenerResponse(ctx context.Context, v any, hdr, trlr metadata.MD) (any, error) {
return &ListenerClientStream{
stream: v.(chatterpb.Chatter_ListenerClient),
}, nil
}
// BuildSummaryFunc builds the remote method to invoke for "chatter" service
// "summary" endpoint.
func BuildSummaryFunc(grpccli chatterpb.ChatterClient, cliopts ...grpc.CallOption) goagrpc.RemoteFunc {
return func(ctx context.Context, reqpb any, opts ...grpc.CallOption) (any, error) {
for _, opt := range cliopts {
opts = append(opts, opt)
}
if reqpb != nil {
return grpccli.Summary(ctx, opts...)
}
return grpccli.Summary(ctx, opts...)
}
}
// EncodeSummaryRequest encodes requests sent to chatter summary endpoint.
func EncodeSummaryRequest(ctx context.Context, v any, md *metadata.MD) (any, error) {
payload, ok := v.(*chatter.SummaryPayload)
if !ok {
return nil, goagrpc.ErrInvalidType("chatter", "summary", "*chatter.SummaryPayload", v)
}
(*md).Append("authorization", payload.Token)
return nil, nil
}
// DecodeSummaryResponse decodes responses from the chatter summary endpoint.
func DecodeSummaryResponse(ctx context.Context, v any, hdr, trlr metadata.MD) (any, error) {
var view string
{
if vals := hdr.Get("goa-view"); len(vals) > 0 {
view = vals[0]
}
}
return &SummaryClientStream{
stream: v.(chatterpb.Chatter_SummaryClient),
view: view,
}, nil
}
// BuildSubscribeFunc builds the remote method to invoke for "chatter" service
// "subscribe" endpoint.
func BuildSubscribeFunc(grpccli chatterpb.ChatterClient, cliopts ...grpc.CallOption) goagrpc.RemoteFunc {
return func(ctx context.Context, reqpb any, opts ...grpc.CallOption) (any, error) {
for _, opt := range cliopts {
opts = append(opts, opt)
}
if reqpb != nil {
return grpccli.Subscribe(ctx, reqpb.(*chatterpb.SubscribeRequest), opts...)
}
return grpccli.Subscribe(ctx, &chatterpb.SubscribeRequest{}, opts...)
}
}
// EncodeSubscribeRequest encodes requests sent to chatter subscribe endpoint.
func EncodeSubscribeRequest(ctx context.Context, v any, md *metadata.MD) (any, error) {
payload, ok := v.(*chatter.SubscribePayload)
if !ok {
return nil, goagrpc.ErrInvalidType("chatter", "subscribe", "*chatter.SubscribePayload", v)
}
(*md).Append("authorization", payload.Token)
return NewProtoSubscribeRequest(), nil
}
// DecodeSubscribeResponse decodes responses from the chatter subscribe
// endpoint.
func DecodeSubscribeResponse(ctx context.Context, v any, hdr, trlr metadata.MD) (any, error) {
return &SubscribeClientStream{
stream: v.(chatterpb.Chatter_SubscribeClient),
}, nil
}
// BuildHistoryFunc builds the remote method to invoke for "chatter" service
// "history" endpoint.
func BuildHistoryFunc(grpccli chatterpb.ChatterClient, cliopts ...grpc.CallOption) goagrpc.RemoteFunc {
return func(ctx context.Context, reqpb any, opts ...grpc.CallOption) (any, error) {
for _, opt := range cliopts {
opts = append(opts, opt)
}
if reqpb != nil {
return grpccli.History(ctx, reqpb.(*chatterpb.HistoryRequest), opts...)
}
return grpccli.History(ctx, &chatterpb.HistoryRequest{}, opts...)
}
}
// EncodeHistoryRequest encodes requests sent to chatter history endpoint.
func EncodeHistoryRequest(ctx context.Context, v any, md *metadata.MD) (any, error) {
payload, ok := v.(*chatter.HistoryPayload)
if !ok {
return nil, goagrpc.ErrInvalidType("chatter", "history", "*chatter.HistoryPayload", v)
}
if payload.View != nil {
(*md).Append("view", *payload.View)
}
(*md).Append("authorization", payload.Token)
return NewProtoHistoryRequest(), nil
}
// DecodeHistoryResponse decodes responses from the chatter history endpoint.
func DecodeHistoryResponse(ctx context.Context, v any, hdr, trlr metadata.MD) (any, error) {
var view string
{
if vals := hdr.Get("goa-view"); len(vals) > 0 {
view = vals[0]
}
}
return &HistoryClientStream{
stream: v.(chatterpb.Chatter_HistoryClient),
view: view,
}, nil
}