-
Notifications
You must be signed in to change notification settings - Fork 3
/
client.go
337 lines (312 loc) · 9.1 KB
/
client.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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
// Code generated by goa v3.15.2, DO NOT EDIT.
//
// package client HTTP transport
//
// Command:
// $ goa gen github.com/artefactual-sdps/enduro/internal/api/design -o
// internal/api
package client
import (
"context"
"net/http"
"time"
"github.com/gorilla/websocket"
goahttp "goa.design/goa/v3/http"
goa "goa.design/goa/v3/pkg"
)
// Client lists the package service endpoint HTTP clients.
type Client struct {
// MonitorRequest Doer is the HTTP client used to make requests to the
// monitor_request endpoint.
MonitorRequestDoer goahttp.Doer
// Monitor Doer is the HTTP client used to make requests to the monitor
// endpoint.
MonitorDoer goahttp.Doer
// List Doer is the HTTP client used to make requests to the list endpoint.
ListDoer goahttp.Doer
// Show Doer is the HTTP client used to make requests to the show endpoint.
ShowDoer goahttp.Doer
// PreservationActions Doer is the HTTP client used to make requests to the
// preservation_actions endpoint.
PreservationActionsDoer goahttp.Doer
// Confirm Doer is the HTTP client used to make requests to the confirm
// endpoint.
ConfirmDoer goahttp.Doer
// Reject Doer is the HTTP client used to make requests to the reject endpoint.
RejectDoer goahttp.Doer
// Move Doer is the HTTP client used to make requests to the move endpoint.
MoveDoer goahttp.Doer
// MoveStatus Doer is the HTTP client used to make requests to the move_status
// endpoint.
MoveStatusDoer goahttp.Doer
// CORS Doer is the HTTP client used to make requests to the endpoint.
CORSDoer goahttp.Doer
// RestoreResponseBody controls whether the response bodies are reset after
// decoding so they can be read again.
RestoreResponseBody bool
scheme string
host string
encoder func(*http.Request) goahttp.Encoder
decoder func(*http.Response) goahttp.Decoder
dialer goahttp.Dialer
configurer *ConnConfigurer
}
// NewClient instantiates HTTP clients for all the package service servers.
func NewClient(
scheme string,
host string,
doer goahttp.Doer,
enc func(*http.Request) goahttp.Encoder,
dec func(*http.Response) goahttp.Decoder,
restoreBody bool,
dialer goahttp.Dialer,
cfn *ConnConfigurer,
) *Client {
if cfn == nil {
cfn = &ConnConfigurer{}
}
return &Client{
MonitorRequestDoer: doer,
MonitorDoer: doer,
ListDoer: doer,
ShowDoer: doer,
PreservationActionsDoer: doer,
ConfirmDoer: doer,
RejectDoer: doer,
MoveDoer: doer,
MoveStatusDoer: doer,
CORSDoer: doer,
RestoreResponseBody: restoreBody,
scheme: scheme,
host: host,
decoder: dec,
encoder: enc,
dialer: dialer,
configurer: cfn,
}
}
// MonitorRequest returns an endpoint that makes HTTP requests to the package
// service monitor_request server.
func (c *Client) MonitorRequest() goa.Endpoint {
var (
encodeRequest = EncodeMonitorRequestRequest(c.encoder)
decodeResponse = DecodeMonitorRequestResponse(c.decoder, c.RestoreResponseBody)
)
return func(ctx context.Context, v any) (any, error) {
req, err := c.BuildMonitorRequestRequest(ctx, v)
if err != nil {
return nil, err
}
err = encodeRequest(req, v)
if err != nil {
return nil, err
}
resp, err := c.MonitorRequestDoer.Do(req)
if err != nil {
return nil, goahttp.ErrRequestError("package", "monitor_request", err)
}
return decodeResponse(resp)
}
}
// Monitor returns an endpoint that makes HTTP requests to the package service
// monitor server.
func (c *Client) Monitor() goa.Endpoint {
var (
encodeRequest = EncodeMonitorRequest(c.encoder)
decodeResponse = DecodeMonitorResponse(c.decoder, c.RestoreResponseBody)
)
return func(ctx context.Context, v any) (any, error) {
req, err := c.BuildMonitorRequest(ctx, v)
if err != nil {
return nil, err
}
err = encodeRequest(req, v)
if err != nil {
return nil, err
}
conn, resp, err := c.dialer.DialContext(ctx, req.URL.String(), req.Header)
if err != nil {
if resp != nil {
return decodeResponse(resp)
}
return nil, goahttp.ErrRequestError("package", "monitor", err)
}
if c.configurer.MonitorFn != nil {
var cancel context.CancelFunc
ctx, cancel = context.WithCancel(ctx)
conn = c.configurer.MonitorFn(conn, cancel)
}
go func() {
<-ctx.Done()
conn.WriteControl(
websocket.CloseMessage,
websocket.FormatCloseMessage(websocket.CloseNormalClosure, "client closing connection"),
time.Now().Add(time.Second),
)
conn.Close()
}()
stream := &MonitorClientStream{conn: conn}
return stream, nil
}
}
// List returns an endpoint that makes HTTP requests to the package service
// list server.
func (c *Client) List() goa.Endpoint {
var (
encodeRequest = EncodeListRequest(c.encoder)
decodeResponse = DecodeListResponse(c.decoder, c.RestoreResponseBody)
)
return func(ctx context.Context, v any) (any, error) {
req, err := c.BuildListRequest(ctx, v)
if err != nil {
return nil, err
}
err = encodeRequest(req, v)
if err != nil {
return nil, err
}
resp, err := c.ListDoer.Do(req)
if err != nil {
return nil, goahttp.ErrRequestError("package", "list", err)
}
return decodeResponse(resp)
}
}
// Show returns an endpoint that makes HTTP requests to the package service
// show server.
func (c *Client) Show() goa.Endpoint {
var (
encodeRequest = EncodeShowRequest(c.encoder)
decodeResponse = DecodeShowResponse(c.decoder, c.RestoreResponseBody)
)
return func(ctx context.Context, v any) (any, error) {
req, err := c.BuildShowRequest(ctx, v)
if err != nil {
return nil, err
}
err = encodeRequest(req, v)
if err != nil {
return nil, err
}
resp, err := c.ShowDoer.Do(req)
if err != nil {
return nil, goahttp.ErrRequestError("package", "show", err)
}
return decodeResponse(resp)
}
}
// PreservationActions returns an endpoint that makes HTTP requests to the
// package service preservation_actions server.
func (c *Client) PreservationActions() goa.Endpoint {
var (
encodeRequest = EncodePreservationActionsRequest(c.encoder)
decodeResponse = DecodePreservationActionsResponse(c.decoder, c.RestoreResponseBody)
)
return func(ctx context.Context, v any) (any, error) {
req, err := c.BuildPreservationActionsRequest(ctx, v)
if err != nil {
return nil, err
}
err = encodeRequest(req, v)
if err != nil {
return nil, err
}
resp, err := c.PreservationActionsDoer.Do(req)
if err != nil {
return nil, goahttp.ErrRequestError("package", "preservation_actions", err)
}
return decodeResponse(resp)
}
}
// Confirm returns an endpoint that makes HTTP requests to the package service
// confirm server.
func (c *Client) Confirm() goa.Endpoint {
var (
encodeRequest = EncodeConfirmRequest(c.encoder)
decodeResponse = DecodeConfirmResponse(c.decoder, c.RestoreResponseBody)
)
return func(ctx context.Context, v any) (any, error) {
req, err := c.BuildConfirmRequest(ctx, v)
if err != nil {
return nil, err
}
err = encodeRequest(req, v)
if err != nil {
return nil, err
}
resp, err := c.ConfirmDoer.Do(req)
if err != nil {
return nil, goahttp.ErrRequestError("package", "confirm", err)
}
return decodeResponse(resp)
}
}
// Reject returns an endpoint that makes HTTP requests to the package service
// reject server.
func (c *Client) Reject() goa.Endpoint {
var (
encodeRequest = EncodeRejectRequest(c.encoder)
decodeResponse = DecodeRejectResponse(c.decoder, c.RestoreResponseBody)
)
return func(ctx context.Context, v any) (any, error) {
req, err := c.BuildRejectRequest(ctx, v)
if err != nil {
return nil, err
}
err = encodeRequest(req, v)
if err != nil {
return nil, err
}
resp, err := c.RejectDoer.Do(req)
if err != nil {
return nil, goahttp.ErrRequestError("package", "reject", err)
}
return decodeResponse(resp)
}
}
// Move returns an endpoint that makes HTTP requests to the package service
// move server.
func (c *Client) Move() goa.Endpoint {
var (
encodeRequest = EncodeMoveRequest(c.encoder)
decodeResponse = DecodeMoveResponse(c.decoder, c.RestoreResponseBody)
)
return func(ctx context.Context, v any) (any, error) {
req, err := c.BuildMoveRequest(ctx, v)
if err != nil {
return nil, err
}
err = encodeRequest(req, v)
if err != nil {
return nil, err
}
resp, err := c.MoveDoer.Do(req)
if err != nil {
return nil, goahttp.ErrRequestError("package", "move", err)
}
return decodeResponse(resp)
}
}
// MoveStatus returns an endpoint that makes HTTP requests to the package
// service move_status server.
func (c *Client) MoveStatus() goa.Endpoint {
var (
encodeRequest = EncodeMoveStatusRequest(c.encoder)
decodeResponse = DecodeMoveStatusResponse(c.decoder, c.RestoreResponseBody)
)
return func(ctx context.Context, v any) (any, error) {
req, err := c.BuildMoveStatusRequest(ctx, v)
if err != nil {
return nil, err
}
err = encodeRequest(req, v)
if err != nil {
return nil, err
}
resp, err := c.MoveStatusDoer.Do(req)
if err != nil {
return nil, goahttp.ErrRequestError("package", "move_status", err)
}
return decodeResponse(resp)
}
}