-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
71 lines (62 loc) · 1.69 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
// Code generated by goa v3.0.3, DO NOT EDIT.
//
// calc client HTTP transport
//
// Command:
// $ goa gen github.com/eric-isakson/goaeric/internal/examples/calc/design -o
// internal/examples/calc
package client
import (
"context"
"net/http"
goahttp "goa.design/goa/v3/http"
goa "goa.design/goa/v3/pkg"
)
// Client lists the calc service endpoint HTTP clients.
type Client struct {
// Add Doer is the HTTP client used to make requests to the add endpoint.
AddDoer 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
}
// NewClient instantiates HTTP clients for all the calc 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,
) *Client {
return &Client{
AddDoer: doer,
RestoreResponseBody: restoreBody,
scheme: scheme,
host: host,
decoder: dec,
encoder: enc,
}
}
// Add returns an endpoint that makes HTTP requests to the calc service add
// server.
func (c *Client) Add() goa.Endpoint {
var (
decodeResponse = DecodeAddResponse(c.decoder, c.RestoreResponseBody)
)
return func(ctx context.Context, v interface{}) (interface{}, error) {
req, err := c.BuildAddRequest(ctx, v)
if err != nil {
return nil, err
}
resp, err := c.AddDoer.Do(req)
if err != nil {
return nil, goahttp.ErrRequestError("calc", "add", err)
}
return decodeResponse(resp)
}
}