forked from goadesign/goa
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultipart_code.go
More file actions
380 lines (359 loc) · 15.1 KB
/
multipart_code.go
File metadata and controls
380 lines (359 loc) · 15.1 KB
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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
package testdata
var MultipartPrimitiveDecoderFuncTypeCode = `// ServiceMultipartPrimitiveMethodMultipartPrimitiveDecoderFunc is the type to
// decode multipart request for the "ServiceMultipartPrimitive" service
// "MethodMultipartPrimitive" endpoint.
type ServiceMultipartPrimitiveMethodMultipartPrimitiveDecoderFunc func(*multipart.Reader, *string) error
`
var MultipartUserTypeDecoderFuncTypeCode = `// ServiceMultipartUserTypeMethodMultipartUserTypeDecoderFunc is the type to
// decode multipart request for the "ServiceMultipartUserType" service
// "MethodMultipartUserType" endpoint.
type ServiceMultipartUserTypeMethodMultipartUserTypeDecoderFunc func(*multipart.Reader, **servicemultipartusertype.MethodMultipartUserTypePayload) error
`
var MultipartArrayTypeDecoderFuncTypeCode = `// ServiceMultipartArrayTypeMethodMultipartArrayTypeDecoderFunc is the type to
// decode multipart request for the "ServiceMultipartArrayType" service
// "MethodMultipartArrayType" endpoint.
type ServiceMultipartArrayTypeMethodMultipartArrayTypeDecoderFunc func(*multipart.Reader, *[]*servicemultipartarraytype.PayloadType) error
`
var MultipartMapTypeDecoderFuncTypeCode = `// ServiceMultipartMapTypeMethodMultipartMapTypeDecoderFunc is the type to
// decode multipart request for the "ServiceMultipartMapType" service
// "MethodMultipartMapType" endpoint.
type ServiceMultipartMapTypeMethodMultipartMapTypeDecoderFunc func(*multipart.Reader, *map[string]int) error
`
var MultipartPrimitiveEncoderFuncTypeCode = `// ServiceMultipartPrimitiveMethodMultipartPrimitiveEncoderFunc is the type to
// encode multipart request for the "ServiceMultipartPrimitive" service
// "MethodMultipartPrimitive" endpoint.
type ServiceMultipartPrimitiveMethodMultipartPrimitiveEncoderFunc func(*multipart.Writer, string) error
`
var MultipartUserTypeEncoderFuncTypeCode = `// ServiceMultipartUserTypeMethodMultipartUserTypeEncoderFunc is the type to
// encode multipart request for the "ServiceMultipartUserType" service
// "MethodMultipartUserType" endpoint.
type ServiceMultipartUserTypeMethodMultipartUserTypeEncoderFunc func(*multipart.Writer, *servicemultipartusertype.MethodMultipartUserTypePayload) error
`
var MultipartArrayTypeEncoderFuncTypeCode = `// ServiceMultipartArrayTypeMethodMultipartArrayTypeEncoderFunc is the type to
// encode multipart request for the "ServiceMultipartArrayType" service
// "MethodMultipartArrayType" endpoint.
type ServiceMultipartArrayTypeMethodMultipartArrayTypeEncoderFunc func(*multipart.Writer, []*servicemultipartarraytype.PayloadType) error
`
var MultipartMapTypeEncoderFuncTypeCode = `// ServiceMultipartMapTypeMethodMultipartMapTypeEncoderFunc is the type to
// encode multipart request for the "ServiceMultipartMapType" service
// "MethodMultipartMapType" endpoint.
type ServiceMultipartMapTypeMethodMultipartMapTypeEncoderFunc func(*multipart.Writer, map[string]int) error
`
var MultipartPrimitiveDecoderFuncCode = `// NewServiceMultipartPrimitiveMethodMultipartPrimitiveDecoder returns a
// decoder to decode the multipart request for the "ServiceMultipartPrimitive"
// service "MethodMultipartPrimitive" endpoint.
func NewServiceMultipartPrimitiveMethodMultipartPrimitiveDecoder(mux goahttp.Muxer, serviceMultipartPrimitiveMethodMultipartPrimitiveDecoderFn ServiceMultipartPrimitiveMethodMultipartPrimitiveDecoderFunc) func(r *http.Request) goahttp.Decoder {
return func(r *http.Request) goahttp.Decoder {
return goahttp.EncodingFunc(func(v any) error {
mr, merr := r.MultipartReader()
if merr != nil {
return merr
}
p := v.(*string)
if err := serviceMultipartPrimitiveMethodMultipartPrimitiveDecoderFn(mr, p); err != nil {
return err
}
return nil
})
}
}
`
var MultipartUserTypeDecoderFuncCode = `// NewServiceMultipartUserTypeMethodMultipartUserTypeDecoder returns a decoder
// to decode the multipart request for the "ServiceMultipartUserType" service
// "MethodMultipartUserType" endpoint.
func NewServiceMultipartUserTypeMethodMultipartUserTypeDecoder(mux goahttp.Muxer, serviceMultipartUserTypeMethodMultipartUserTypeDecoderFn ServiceMultipartUserTypeMethodMultipartUserTypeDecoderFunc) func(r *http.Request) goahttp.Decoder {
return func(r *http.Request) goahttp.Decoder {
return goahttp.EncodingFunc(func(v any) error {
mr, merr := r.MultipartReader()
if merr != nil {
return merr
}
p := v.(**servicemultipartusertype.MethodMultipartUserTypePayload)
if err := serviceMultipartUserTypeMethodMultipartUserTypeDecoderFn(mr, p); err != nil {
return err
}
return nil
})
}
}
`
var MultipartArrayTypeDecoderFuncCode = `// NewServiceMultipartArrayTypeMethodMultipartArrayTypeDecoder returns a
// decoder to decode the multipart request for the "ServiceMultipartArrayType"
// service "MethodMultipartArrayType" endpoint.
func NewServiceMultipartArrayTypeMethodMultipartArrayTypeDecoder(mux goahttp.Muxer, serviceMultipartArrayTypeMethodMultipartArrayTypeDecoderFn ServiceMultipartArrayTypeMethodMultipartArrayTypeDecoderFunc) func(r *http.Request) goahttp.Decoder {
return func(r *http.Request) goahttp.Decoder {
return goahttp.EncodingFunc(func(v any) error {
mr, merr := r.MultipartReader()
if merr != nil {
return merr
}
p := v.(*[]*servicemultipartarraytype.PayloadType)
if err := serviceMultipartArrayTypeMethodMultipartArrayTypeDecoderFn(mr, p); err != nil {
return err
}
return nil
})
}
}
`
var MultipartMapTypeDecoderFuncCode = `// NewServiceMultipartMapTypeMethodMultipartMapTypeDecoder returns a decoder to
// decode the multipart request for the "ServiceMultipartMapType" service
// "MethodMultipartMapType" endpoint.
func NewServiceMultipartMapTypeMethodMultipartMapTypeDecoder(mux goahttp.Muxer, serviceMultipartMapTypeMethodMultipartMapTypeDecoderFn ServiceMultipartMapTypeMethodMultipartMapTypeDecoderFunc) func(r *http.Request) goahttp.Decoder {
return func(r *http.Request) goahttp.Decoder {
return goahttp.EncodingFunc(func(v any) error {
mr, merr := r.MultipartReader()
if merr != nil {
return merr
}
p := v.(*map[string]int)
if err := serviceMultipartMapTypeMethodMultipartMapTypeDecoderFn(mr, p); err != nil {
return err
}
return nil
})
}
}
`
var MultipartWithParamDecoderFuncCode = `// NewServiceMultipartWithParamMethodMultipartWithParamDecoder returns a
// decoder to decode the multipart request for the "ServiceMultipartWithParam"
// service "MethodMultipartWithParam" endpoint.
func NewServiceMultipartWithParamMethodMultipartWithParamDecoder(mux goahttp.Muxer, serviceMultipartWithParamMethodMultipartWithParamDecoderFn ServiceMultipartWithParamMethodMultipartWithParamDecoderFunc) func(r *http.Request) goahttp.Decoder {
return func(r *http.Request) goahttp.Decoder {
return goahttp.EncodingFunc(func(v any) error {
mr, merr := r.MultipartReader()
if merr != nil {
return merr
}
p := v.(**servicemultipartwithparam.PayloadType)
if err := serviceMultipartWithParamMethodMultipartWithParamDecoderFn(mr, p); err != nil {
return err
}
var (
c2 map[int][]string
err error
)
{
c2Raw := r.URL.Query()
if len(c2Raw) == 0 {
err = goa.MergeErrors(err, goa.MissingFieldError("c", "query string"))
}
for keyRaw, valRaw := range c2Raw {
if strings.HasPrefix(keyRaw, "c[") {
if c2 == nil {
c2 = make(map[int][]string)
}
var keya int
{
openIdx := strings.IndexRune(keyRaw, '[')
closeIdx := strings.IndexRune(keyRaw, ']')
if openIdx == -1 || closeIdx == -1 || closeIdx <= openIdx {
err = goa.MergeErrors(err, goa.DecodePayloadError("invalid query string: malformed brackets"))
} else {
keyaRaw := keyRaw[openIdx+1 : closeIdx]
v, err2 := strconv.ParseInt(keyaRaw, 10, strconv.IntSize)
if err2 != nil {
err = goa.MergeErrors(err, goa.InvalidFieldTypeError("query", keyaRaw, "integer"))
}
keya = int(v)
}
}
c2[keya] = valRaw
}
}
}
if err != nil {
return err
}
(*p).C = c2
return nil
})
}
}
`
var MultipartWithParamsAndHeadersDecoderFuncCode = `// NewServiceMultipartWithParamsAndHeadersMethodMultipartWithParamsAndHeadersDecoder
// returns a decoder to decode the multipart request for the
// "ServiceMultipartWithParamsAndHeaders" service
// "MethodMultipartWithParamsAndHeaders" endpoint.
func NewServiceMultipartWithParamsAndHeadersMethodMultipartWithParamsAndHeadersDecoder(mux goahttp.Muxer, serviceMultipartWithParamsAndHeadersMethodMultipartWithParamsAndHeadersDecoderFn ServiceMultipartWithParamsAndHeadersMethodMultipartWithParamsAndHeadersDecoderFunc) func(r *http.Request) goahttp.Decoder {
return func(r *http.Request) goahttp.Decoder {
return goahttp.EncodingFunc(func(v any) error {
mr, merr := r.MultipartReader()
if merr != nil {
return merr
}
p := v.(**servicemultipartwithparamsandheaders.PayloadType)
if err := serviceMultipartWithParamsAndHeadersMethodMultipartWithParamsAndHeadersDecoderFn(mr, p); err != nil {
return err
}
var (
a string
c2 map[int][]string
b *string
err error
params = mux.Vars(r)
)
a = params["a"]
err = goa.MergeErrors(err, goa.ValidatePattern("a", a, "patterna"))
{
c2Raw := r.URL.Query()
if len(c2Raw) == 0 {
err = goa.MergeErrors(err, goa.MissingFieldError("c", "query string"))
}
for keyRaw, valRaw := range c2Raw {
if strings.HasPrefix(keyRaw, "c[") {
if c2 == nil {
c2 = make(map[int][]string)
}
var keya int
{
openIdx := strings.IndexRune(keyRaw, '[')
closeIdx := strings.IndexRune(keyRaw, ']')
if openIdx == -1 || closeIdx == -1 || closeIdx <= openIdx {
err = goa.MergeErrors(err, goa.DecodePayloadError("invalid query string: malformed brackets"))
} else {
keyaRaw := keyRaw[openIdx+1 : closeIdx]
v, err2 := strconv.ParseInt(keyaRaw, 10, strconv.IntSize)
if err2 != nil {
err = goa.MergeErrors(err, goa.InvalidFieldTypeError("query", keyaRaw, "integer"))
}
keya = int(v)
}
}
c2[keya] = valRaw
}
}
}
bRaw := r.Header.Get("Authorization")
if bRaw != "" {
b = &bRaw
}
if b != nil {
err = goa.MergeErrors(err, goa.ValidatePattern("b", *b, "patternb"))
}
if err != nil {
return err
}
(*p).A = a
(*p).C = c2
(*p).B = b
return nil
})
}
}
`
var MultipartPrimitiveEncoderFuncCode = `// NewServiceMultipartPrimitiveMethodMultipartPrimitiveEncoder returns an
// encoder to encode the multipart request for the "ServiceMultipartPrimitive"
// service "MethodMultipartPrimitive" endpoint.
func NewServiceMultipartPrimitiveMethodMultipartPrimitiveEncoder(encoderFn ServiceMultipartPrimitiveMethodMultipartPrimitiveEncoderFunc) func(r *http.Request) goahttp.Encoder {
return func(r *http.Request) goahttp.Encoder {
body := &bytes.Buffer{}
mw := multipart.NewWriter(body)
return goahttp.EncodingFunc(func(v any) error {
p := v.(string)
if err := encoderFn(mw, p); err != nil {
return err
}
r.Body = io.NopCloser(body)
r.Header.Set("Content-Type", mw.FormDataContentType())
return mw.Close()
})
}
}
`
var MultipartUserTypeEncoderFuncCode = `// NewServiceMultipartUserTypeMethodMultipartUserTypeEncoder returns an encoder
// to encode the multipart request for the "ServiceMultipartUserType" service
// "MethodMultipartUserType" endpoint.
func NewServiceMultipartUserTypeMethodMultipartUserTypeEncoder(encoderFn ServiceMultipartUserTypeMethodMultipartUserTypeEncoderFunc) func(r *http.Request) goahttp.Encoder {
return func(r *http.Request) goahttp.Encoder {
body := &bytes.Buffer{}
mw := multipart.NewWriter(body)
return goahttp.EncodingFunc(func(v any) error {
p := v.(*servicemultipartusertype.MethodMultipartUserTypePayload)
if err := encoderFn(mw, p); err != nil {
return err
}
r.Body = io.NopCloser(body)
r.Header.Set("Content-Type", mw.FormDataContentType())
return mw.Close()
})
}
}
`
var MultipartArrayTypeEncoderFuncCode = `// NewServiceMultipartArrayTypeMethodMultipartArrayTypeEncoder returns an
// encoder to encode the multipart request for the "ServiceMultipartArrayType"
// service "MethodMultipartArrayType" endpoint.
func NewServiceMultipartArrayTypeMethodMultipartArrayTypeEncoder(encoderFn ServiceMultipartArrayTypeMethodMultipartArrayTypeEncoderFunc) func(r *http.Request) goahttp.Encoder {
return func(r *http.Request) goahttp.Encoder {
body := &bytes.Buffer{}
mw := multipart.NewWriter(body)
return goahttp.EncodingFunc(func(v any) error {
p := v.([]*servicemultipartarraytype.PayloadType)
if err := encoderFn(mw, p); err != nil {
return err
}
r.Body = io.NopCloser(body)
r.Header.Set("Content-Type", mw.FormDataContentType())
return mw.Close()
})
}
}
`
var MultipartMapTypeEncoderFuncCode = `// NewServiceMultipartMapTypeMethodMultipartMapTypeEncoder returns an encoder
// to encode the multipart request for the "ServiceMultipartMapType" service
// "MethodMultipartMapType" endpoint.
func NewServiceMultipartMapTypeMethodMultipartMapTypeEncoder(encoderFn ServiceMultipartMapTypeMethodMultipartMapTypeEncoderFunc) func(r *http.Request) goahttp.Encoder {
return func(r *http.Request) goahttp.Encoder {
body := &bytes.Buffer{}
mw := multipart.NewWriter(body)
return goahttp.EncodingFunc(func(v any) error {
p := v.(map[string]int)
if err := encoderFn(mw, p); err != nil {
return err
}
r.Body = io.NopCloser(body)
r.Header.Set("Content-Type", mw.FormDataContentType())
return mw.Close()
})
}
}
`
var MultipartWithParamEncoderFuncCode = `// NewServiceMultipartWithParamMethodMultipartWithParamEncoder returns an
// encoder to encode the multipart request for the "ServiceMultipartWithParam"
// service "MethodMultipartWithParam" endpoint.
func NewServiceMultipartWithParamMethodMultipartWithParamEncoder(encoderFn ServiceMultipartWithParamMethodMultipartWithParamEncoderFunc) func(r *http.Request) goahttp.Encoder {
return func(r *http.Request) goahttp.Encoder {
body := &bytes.Buffer{}
mw := multipart.NewWriter(body)
return goahttp.EncodingFunc(func(v any) error {
p := v.(*servicemultipartwithparam.PayloadType)
if err := encoderFn(mw, p); err != nil {
return err
}
r.Body = io.NopCloser(body)
r.Header.Set("Content-Type", mw.FormDataContentType())
return mw.Close()
})
}
}
`
var MultipartWithParamsAndHeadersEncoderFuncCode = `// NewServiceMultipartWithParamsAndHeadersMethodMultipartWithParamsAndHeadersEncoder
// returns an encoder to encode the multipart request for the
// "ServiceMultipartWithParamsAndHeaders" service
// "MethodMultipartWithParamsAndHeaders" endpoint.
func NewServiceMultipartWithParamsAndHeadersMethodMultipartWithParamsAndHeadersEncoder(encoderFn ServiceMultipartWithParamsAndHeadersMethodMultipartWithParamsAndHeadersEncoderFunc) func(r *http.Request) goahttp.Encoder {
return func(r *http.Request) goahttp.Encoder {
body := &bytes.Buffer{}
mw := multipart.NewWriter(body)
return goahttp.EncodingFunc(func(v any) error {
p := v.(*servicemultipartwithparamsandheaders.PayloadType)
if err := encoderFn(mw, p); err != nil {
return err
}
r.Body = io.NopCloser(body)
r.Header.Set("Content-Type", mw.FormDataContentType())
return mw.Close()
})
}
}
`