/
client.go
162 lines (148 loc) · 4.44 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
// Code generated by goa v2.2.4, DO NOT EDIT.
//
// secured_service client HTTP transport
//
// Command:
// $ goa gen goa.design/examples/security/design -o
// $(GOPATH)/src/goa.design/examples/security
package client
import (
"context"
"net/http"
goa "goa.design/goa"
goahttp "goa.design/goa/http"
)
// Client lists the secured_service service endpoint HTTP clients.
type Client struct {
// Signin Doer is the HTTP client used to make requests to the signin endpoint.
SigninDoer goahttp.Doer
// Secure Doer is the HTTP client used to make requests to the secure endpoint.
SecureDoer goahttp.Doer
// DoublySecure Doer is the HTTP client used to make requests to the
// doubly_secure endpoint.
DoublySecureDoer goahttp.Doer
// AlsoDoublySecure Doer is the HTTP client used to make requests to the
// also_doubly_secure endpoint.
AlsoDoublySecureDoer 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 secured_service 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{
SigninDoer: doer,
SecureDoer: doer,
DoublySecureDoer: doer,
AlsoDoublySecureDoer: doer,
RestoreResponseBody: restoreBody,
scheme: scheme,
host: host,
decoder: dec,
encoder: enc,
}
}
// Signin returns an endpoint that makes HTTP requests to the secured_service
// service signin server.
func (c *Client) Signin() goa.Endpoint {
var (
encodeRequest = EncodeSigninRequest(c.encoder)
decodeResponse = DecodeSigninResponse(c.decoder, c.RestoreResponseBody)
)
return func(ctx context.Context, v interface{}) (interface{}, error) {
req, err := c.BuildSigninRequest(ctx, v)
if err != nil {
return nil, err
}
err = encodeRequest(req, v)
if err != nil {
return nil, err
}
resp, err := c.SigninDoer.Do(req)
if err != nil {
return nil, goahttp.ErrRequestError("secured_service", "signin", err)
}
return decodeResponse(resp)
}
}
// Secure returns an endpoint that makes HTTP requests to the secured_service
// service secure server.
func (c *Client) Secure() goa.Endpoint {
var (
encodeRequest = EncodeSecureRequest(c.encoder)
decodeResponse = DecodeSecureResponse(c.decoder, c.RestoreResponseBody)
)
return func(ctx context.Context, v interface{}) (interface{}, error) {
req, err := c.BuildSecureRequest(ctx, v)
if err != nil {
return nil, err
}
err = encodeRequest(req, v)
if err != nil {
return nil, err
}
resp, err := c.SecureDoer.Do(req)
if err != nil {
return nil, goahttp.ErrRequestError("secured_service", "secure", err)
}
return decodeResponse(resp)
}
}
// DoublySecure returns an endpoint that makes HTTP requests to the
// secured_service service doubly_secure server.
func (c *Client) DoublySecure() goa.Endpoint {
var (
encodeRequest = EncodeDoublySecureRequest(c.encoder)
decodeResponse = DecodeDoublySecureResponse(c.decoder, c.RestoreResponseBody)
)
return func(ctx context.Context, v interface{}) (interface{}, error) {
req, err := c.BuildDoublySecureRequest(ctx, v)
if err != nil {
return nil, err
}
err = encodeRequest(req, v)
if err != nil {
return nil, err
}
resp, err := c.DoublySecureDoer.Do(req)
if err != nil {
return nil, goahttp.ErrRequestError("secured_service", "doubly_secure", err)
}
return decodeResponse(resp)
}
}
// AlsoDoublySecure returns an endpoint that makes HTTP requests to the
// secured_service service also_doubly_secure server.
func (c *Client) AlsoDoublySecure() goa.Endpoint {
var (
encodeRequest = EncodeAlsoDoublySecureRequest(c.encoder)
decodeResponse = DecodeAlsoDoublySecureResponse(c.decoder, c.RestoreResponseBody)
)
return func(ctx context.Context, v interface{}) (interface{}, error) {
req, err := c.BuildAlsoDoublySecureRequest(ctx, v)
if err != nil {
return nil, err
}
err = encodeRequest(req, v)
if err != nil {
return nil, err
}
resp, err := c.AlsoDoublySecureDoer.Do(req)
if err != nil {
return nil, goahttp.ErrRequestError("secured_service", "also_doubly_secure", err)
}
return decodeResponse(resp)
}
}