1
2
3
4 package formrecognizer
5
6
7
8
9
10
11
12 import (
13 "context"
14 "github.com/Azure/go-autorest/autorest"
15 "github.com/Azure/go-autorest/autorest/azure"
16 "github.com/Azure/go-autorest/autorest/validation"
17 "github.com/Azure/go-autorest/tracing"
18 "github.com/gofrs/uuid"
19 "io"
20 "net/http"
21 )
22
23
24 type BaseClient struct {
25 autorest.Client
26 Endpoint string
27 }
28
29
30 func New(endpoint string) BaseClient {
31 return NewWithoutDefaults(endpoint)
32 }
33
34
35 func NewWithoutDefaults(endpoint string) BaseClient {
36 return BaseClient{
37 Client: autorest.NewClientWithUserAgent(UserAgent()),
38 Endpoint: endpoint,
39 }
40 }
41
42
43
44
45
46
47
48 func (client BaseClient) AnalyzeWithCustomModel(ctx context.Context, ID uuid.UUID, formStream io.ReadCloser, keys []string) (result AnalyzeResult, err error) {
49 if tracing.IsEnabled() {
50 ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.AnalyzeWithCustomModel")
51 defer func() {
52 sc := -1
53 if result.Response.Response != nil {
54 sc = result.Response.Response.StatusCode
55 }
56 tracing.EndSpan(ctx, sc, err)
57 }()
58 }
59 req, err := client.AnalyzeWithCustomModelPreparer(ctx, ID, formStream, keys)
60 if err != nil {
61 err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "AnalyzeWithCustomModel", nil, "Failure preparing request")
62 return
63 }
64
65 resp, err := client.AnalyzeWithCustomModelSender(req)
66 if err != nil {
67 result.Response = autorest.Response{Response: resp}
68 err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "AnalyzeWithCustomModel", resp, "Failure sending request")
69 return
70 }
71
72 result, err = client.AnalyzeWithCustomModelResponder(resp)
73 if err != nil {
74 err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "AnalyzeWithCustomModel", resp, "Failure responding to request")
75 return
76 }
77
78 return
79 }
80
81
82 func (client BaseClient) AnalyzeWithCustomModelPreparer(ctx context.Context, ID uuid.UUID, formStream io.ReadCloser, keys []string) (*http.Request, error) {
83 urlParameters := map[string]interface{}{
84 "Endpoint": client.Endpoint,
85 }
86
87 pathParameters := map[string]interface{}{
88 "id": autorest.Encode("path", ID),
89 }
90
91 queryParameters := map[string]interface{}{}
92 if keys != nil && len(keys) > 0 {
93 queryParameters["keys"] = autorest.Encode("query", keys, ",")
94 }
95
96 formDataParameters := map[string]interface{}{
97 "form_stream": formStream,
98 }
99
100 preparer := autorest.CreatePreparer(
101 autorest.AsPost(),
102 autorest.WithCustomBaseURL("{Endpoint}/formrecognizer/v1.0-preview", urlParameters),
103 autorest.WithPathParameters("/custom/models/{id}/analyze", pathParameters),
104 autorest.WithQueryParameters(queryParameters),
105 autorest.WithMultiPartFormData(formDataParameters))
106 return preparer.Prepare((&http.Request{}).WithContext(ctx))
107 }
108
109
110
111 func (client BaseClient) AnalyzeWithCustomModelSender(req *http.Request) (*http.Response, error) {
112 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
113 }
114
115
116
117 func (client BaseClient) AnalyzeWithCustomModelResponder(resp *http.Response) (result AnalyzeResult, err error) {
118 err = autorest.Respond(
119 resp,
120 azure.WithErrorUnlessStatusCode(http.StatusOK),
121 autorest.ByUnmarshallingJSON(&result),
122 autorest.ByClosing())
123 result.Response = autorest.Response{Response: resp}
124 return
125 }
126
127
128
129
130
131 func (client BaseClient) BatchReadReceipt(ctx context.Context, imageURL ImageURL) (result autorest.Response, err error) {
132 if tracing.IsEnabled() {
133 ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.BatchReadReceipt")
134 defer func() {
135 sc := -1
136 if result.Response != nil {
137 sc = result.Response.StatusCode
138 }
139 tracing.EndSpan(ctx, sc, err)
140 }()
141 }
142 if err := validation.Validate([]validation.Validation{
143 {TargetValue: imageURL,
144 Constraints: []validation.Constraint{{Target: "imageURL.URL", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
145 return result, validation.NewError("formrecognizer.BaseClient", "BatchReadReceipt", err.Error())
146 }
147
148 req, err := client.BatchReadReceiptPreparer(ctx, imageURL)
149 if err != nil {
150 err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "BatchReadReceipt", nil, "Failure preparing request")
151 return
152 }
153
154 resp, err := client.BatchReadReceiptSender(req)
155 if err != nil {
156 result.Response = resp
157 err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "BatchReadReceipt", resp, "Failure sending request")
158 return
159 }
160
161 result, err = client.BatchReadReceiptResponder(resp)
162 if err != nil {
163 err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "BatchReadReceipt", resp, "Failure responding to request")
164 return
165 }
166
167 return
168 }
169
170
171 func (client BaseClient) BatchReadReceiptPreparer(ctx context.Context, imageURL ImageURL) (*http.Request, error) {
172 urlParameters := map[string]interface{}{
173 "Endpoint": client.Endpoint,
174 }
175
176 preparer := autorest.CreatePreparer(
177 autorest.AsContentType("application/json; charset=utf-8"),
178 autorest.AsPost(),
179 autorest.WithCustomBaseURL("{Endpoint}/formrecognizer/v1.0-preview", urlParameters),
180 autorest.WithPath("/prebuilt/receipt/asyncBatchAnalyze"),
181 autorest.WithJSON(imageURL))
182 return preparer.Prepare((&http.Request{}).WithContext(ctx))
183 }
184
185
186
187 func (client BaseClient) BatchReadReceiptSender(req *http.Request) (*http.Response, error) {
188 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
189 }
190
191
192
193 func (client BaseClient) BatchReadReceiptResponder(resp *http.Response) (result autorest.Response, err error) {
194 err = autorest.Respond(
195 resp,
196 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
197 autorest.ByClosing())
198 result.Response = resp
199 return
200 }
201
202
203
204
205
206
207 func (client BaseClient) BatchReadReceiptInStream(ctx context.Context, imageParameter io.ReadCloser) (result autorest.Response, err error) {
208 if tracing.IsEnabled() {
209 ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.BatchReadReceiptInStream")
210 defer func() {
211 sc := -1
212 if result.Response != nil {
213 sc = result.Response.StatusCode
214 }
215 tracing.EndSpan(ctx, sc, err)
216 }()
217 }
218 req, err := client.BatchReadReceiptInStreamPreparer(ctx, imageParameter)
219 if err != nil {
220 err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "BatchReadReceiptInStream", nil, "Failure preparing request")
221 return
222 }
223
224 resp, err := client.BatchReadReceiptInStreamSender(req)
225 if err != nil {
226 result.Response = resp
227 err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "BatchReadReceiptInStream", resp, "Failure sending request")
228 return
229 }
230
231 result, err = client.BatchReadReceiptInStreamResponder(resp)
232 if err != nil {
233 err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "BatchReadReceiptInStream", resp, "Failure responding to request")
234 return
235 }
236
237 return
238 }
239
240
241 func (client BaseClient) BatchReadReceiptInStreamPreparer(ctx context.Context, imageParameter io.ReadCloser) (*http.Request, error) {
242 urlParameters := map[string]interface{}{
243 "Endpoint": client.Endpoint,
244 }
245
246 preparer := autorest.CreatePreparer(
247 autorest.AsContentType("application/octet-stream"),
248 autorest.AsPost(),
249 autorest.WithCustomBaseURL("{Endpoint}/formrecognizer/v1.0-preview", urlParameters),
250 autorest.WithPath("/prebuilt/receipt/asyncBatchAnalyze"),
251 autorest.WithFile(imageParameter))
252 return preparer.Prepare((&http.Request{}).WithContext(ctx))
253 }
254
255
256
257 func (client BaseClient) BatchReadReceiptInStreamSender(req *http.Request) (*http.Response, error) {
258 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
259 }
260
261
262
263 func (client BaseClient) BatchReadReceiptInStreamResponder(resp *http.Response) (result autorest.Response, err error) {
264 err = autorest.Respond(
265 resp,
266 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
267 autorest.ByClosing())
268 result.Response = resp
269 return
270 }
271
272
273
274
275 func (client BaseClient) DeleteCustomModel(ctx context.Context, ID uuid.UUID) (result autorest.Response, err error) {
276 if tracing.IsEnabled() {
277 ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.DeleteCustomModel")
278 defer func() {
279 sc := -1
280 if result.Response != nil {
281 sc = result.Response.StatusCode
282 }
283 tracing.EndSpan(ctx, sc, err)
284 }()
285 }
286 req, err := client.DeleteCustomModelPreparer(ctx, ID)
287 if err != nil {
288 err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "DeleteCustomModel", nil, "Failure preparing request")
289 return
290 }
291
292 resp, err := client.DeleteCustomModelSender(req)
293 if err != nil {
294 result.Response = resp
295 err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "DeleteCustomModel", resp, "Failure sending request")
296 return
297 }
298
299 result, err = client.DeleteCustomModelResponder(resp)
300 if err != nil {
301 err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "DeleteCustomModel", resp, "Failure responding to request")
302 return
303 }
304
305 return
306 }
307
308
309 func (client BaseClient) DeleteCustomModelPreparer(ctx context.Context, ID uuid.UUID) (*http.Request, error) {
310 urlParameters := map[string]interface{}{
311 "Endpoint": client.Endpoint,
312 }
313
314 pathParameters := map[string]interface{}{
315 "id": autorest.Encode("path", ID),
316 }
317
318 preparer := autorest.CreatePreparer(
319 autorest.AsDelete(),
320 autorest.WithCustomBaseURL("{Endpoint}/formrecognizer/v1.0-preview", urlParameters),
321 autorest.WithPathParameters("/custom/models/{id}", pathParameters))
322 return preparer.Prepare((&http.Request{}).WithContext(ctx))
323 }
324
325
326
327 func (client BaseClient) DeleteCustomModelSender(req *http.Request) (*http.Response, error) {
328 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
329 }
330
331
332
333 func (client BaseClient) DeleteCustomModelResponder(resp *http.Response) (result autorest.Response, err error) {
334 err = autorest.Respond(
335 resp,
336 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
337 autorest.ByClosing())
338 result.Response = resp
339 return
340 }
341
342
343
344
345 func (client BaseClient) GetCustomModel(ctx context.Context, ID uuid.UUID) (result ModelResult, err error) {
346 if tracing.IsEnabled() {
347 ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.GetCustomModel")
348 defer func() {
349 sc := -1
350 if result.Response.Response != nil {
351 sc = result.Response.Response.StatusCode
352 }
353 tracing.EndSpan(ctx, sc, err)
354 }()
355 }
356 req, err := client.GetCustomModelPreparer(ctx, ID)
357 if err != nil {
358 err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "GetCustomModel", nil, "Failure preparing request")
359 return
360 }
361
362 resp, err := client.GetCustomModelSender(req)
363 if err != nil {
364 result.Response = autorest.Response{Response: resp}
365 err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "GetCustomModel", resp, "Failure sending request")
366 return
367 }
368
369 result, err = client.GetCustomModelResponder(resp)
370 if err != nil {
371 err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "GetCustomModel", resp, "Failure responding to request")
372 return
373 }
374
375 return
376 }
377
378
379 func (client BaseClient) GetCustomModelPreparer(ctx context.Context, ID uuid.UUID) (*http.Request, error) {
380 urlParameters := map[string]interface{}{
381 "Endpoint": client.Endpoint,
382 }
383
384 pathParameters := map[string]interface{}{
385 "id": autorest.Encode("path", ID),
386 }
387
388 preparer := autorest.CreatePreparer(
389 autorest.AsGet(),
390 autorest.WithCustomBaseURL("{Endpoint}/formrecognizer/v1.0-preview", urlParameters),
391 autorest.WithPathParameters("/custom/models/{id}", pathParameters))
392 return preparer.Prepare((&http.Request{}).WithContext(ctx))
393 }
394
395
396
397 func (client BaseClient) GetCustomModelSender(req *http.Request) (*http.Response, error) {
398 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
399 }
400
401
402
403 func (client BaseClient) GetCustomModelResponder(resp *http.Response) (result ModelResult, err error) {
404 err = autorest.Respond(
405 resp,
406 azure.WithErrorUnlessStatusCode(http.StatusOK),
407 autorest.ByUnmarshallingJSON(&result),
408 autorest.ByClosing())
409 result.Response = autorest.Response{Response: resp}
410 return
411 }
412
413
414 func (client BaseClient) GetCustomModels(ctx context.Context) (result ModelsResult, err error) {
415 if tracing.IsEnabled() {
416 ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.GetCustomModels")
417 defer func() {
418 sc := -1
419 if result.Response.Response != nil {
420 sc = result.Response.Response.StatusCode
421 }
422 tracing.EndSpan(ctx, sc, err)
423 }()
424 }
425 req, err := client.GetCustomModelsPreparer(ctx)
426 if err != nil {
427 err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "GetCustomModels", nil, "Failure preparing request")
428 return
429 }
430
431 resp, err := client.GetCustomModelsSender(req)
432 if err != nil {
433 result.Response = autorest.Response{Response: resp}
434 err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "GetCustomModels", resp, "Failure sending request")
435 return
436 }
437
438 result, err = client.GetCustomModelsResponder(resp)
439 if err != nil {
440 err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "GetCustomModels", resp, "Failure responding to request")
441 return
442 }
443
444 return
445 }
446
447
448 func (client BaseClient) GetCustomModelsPreparer(ctx context.Context) (*http.Request, error) {
449 urlParameters := map[string]interface{}{
450 "Endpoint": client.Endpoint,
451 }
452
453 preparer := autorest.CreatePreparer(
454 autorest.AsGet(),
455 autorest.WithCustomBaseURL("{Endpoint}/formrecognizer/v1.0-preview", urlParameters),
456 autorest.WithPath("/custom/models"))
457 return preparer.Prepare((&http.Request{}).WithContext(ctx))
458 }
459
460
461
462 func (client BaseClient) GetCustomModelsSender(req *http.Request) (*http.Response, error) {
463 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
464 }
465
466
467
468 func (client BaseClient) GetCustomModelsResponder(resp *http.Response) (result ModelsResult, err error) {
469 err = autorest.Respond(
470 resp,
471 azure.WithErrorUnlessStatusCode(http.StatusOK),
472 autorest.ByUnmarshallingJSON(&result),
473 autorest.ByClosing())
474 result.Response = autorest.Response{Response: resp}
475 return
476 }
477
478
479
480
481
482 func (client BaseClient) GetExtractedKeys(ctx context.Context, ID uuid.UUID) (result KeysResult, err error) {
483 if tracing.IsEnabled() {
484 ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.GetExtractedKeys")
485 defer func() {
486 sc := -1
487 if result.Response.Response != nil {
488 sc = result.Response.Response.StatusCode
489 }
490 tracing.EndSpan(ctx, sc, err)
491 }()
492 }
493 req, err := client.GetExtractedKeysPreparer(ctx, ID)
494 if err != nil {
495 err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "GetExtractedKeys", nil, "Failure preparing request")
496 return
497 }
498
499 resp, err := client.GetExtractedKeysSender(req)
500 if err != nil {
501 result.Response = autorest.Response{Response: resp}
502 err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "GetExtractedKeys", resp, "Failure sending request")
503 return
504 }
505
506 result, err = client.GetExtractedKeysResponder(resp)
507 if err != nil {
508 err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "GetExtractedKeys", resp, "Failure responding to request")
509 return
510 }
511
512 return
513 }
514
515
516 func (client BaseClient) GetExtractedKeysPreparer(ctx context.Context, ID uuid.UUID) (*http.Request, error) {
517 urlParameters := map[string]interface{}{
518 "Endpoint": client.Endpoint,
519 }
520
521 pathParameters := map[string]interface{}{
522 "id": autorest.Encode("path", ID),
523 }
524
525 preparer := autorest.CreatePreparer(
526 autorest.AsGet(),
527 autorest.WithCustomBaseURL("{Endpoint}/formrecognizer/v1.0-preview", urlParameters),
528 autorest.WithPathParameters("/custom/models/{id}/keys", pathParameters))
529 return preparer.Prepare((&http.Request{}).WithContext(ctx))
530 }
531
532
533
534 func (client BaseClient) GetExtractedKeysSender(req *http.Request) (*http.Response, error) {
535 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
536 }
537
538
539
540 func (client BaseClient) GetExtractedKeysResponder(resp *http.Response) (result KeysResult, err error) {
541 err = autorest.Respond(
542 resp,
543 azure.WithErrorUnlessStatusCode(http.StatusOK),
544 autorest.ByUnmarshallingJSON(&result),
545 autorest.ByClosing())
546 result.Response = autorest.Response{Response: resp}
547 return
548 }
549
550
551
552
553
554
555 func (client BaseClient) GetReadReceiptResult(ctx context.Context, operationID string) (result ReadReceiptResult, err error) {
556 if tracing.IsEnabled() {
557 ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.GetReadReceiptResult")
558 defer func() {
559 sc := -1
560 if result.Response.Response != nil {
561 sc = result.Response.Response.StatusCode
562 }
563 tracing.EndSpan(ctx, sc, err)
564 }()
565 }
566 req, err := client.GetReadReceiptResultPreparer(ctx, operationID)
567 if err != nil {
568 err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "GetReadReceiptResult", nil, "Failure preparing request")
569 return
570 }
571
572 resp, err := client.GetReadReceiptResultSender(req)
573 if err != nil {
574 result.Response = autorest.Response{Response: resp}
575 err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "GetReadReceiptResult", resp, "Failure sending request")
576 return
577 }
578
579 result, err = client.GetReadReceiptResultResponder(resp)
580 if err != nil {
581 err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "GetReadReceiptResult", resp, "Failure responding to request")
582 return
583 }
584
585 return
586 }
587
588
589 func (client BaseClient) GetReadReceiptResultPreparer(ctx context.Context, operationID string) (*http.Request, error) {
590 urlParameters := map[string]interface{}{
591 "Endpoint": client.Endpoint,
592 }
593
594 pathParameters := map[string]interface{}{
595 "operationId": autorest.Encode("path", operationID),
596 }
597
598 preparer := autorest.CreatePreparer(
599 autorest.AsGet(),
600 autorest.WithCustomBaseURL("{Endpoint}/formrecognizer/v1.0-preview", urlParameters),
601 autorest.WithPathParameters("/prebuilt/receipt/operations/{operationId}", pathParameters))
602 return preparer.Prepare((&http.Request{}).WithContext(ctx))
603 }
604
605
606
607 func (client BaseClient) GetReadReceiptResultSender(req *http.Request) (*http.Response, error) {
608 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
609 }
610
611
612
613 func (client BaseClient) GetReadReceiptResultResponder(resp *http.Response) (result ReadReceiptResult, err error) {
614 err = autorest.Respond(
615 resp,
616 azure.WithErrorUnlessStatusCode(http.StatusOK),
617 autorest.ByUnmarshallingJSON(&result),
618 autorest.ByClosing())
619 result.Response = autorest.Response{Response: resp}
620 return
621 }
622
623
624
625
626
627
628
629
630
631
632
633
634 func (client BaseClient) TrainCustomModel(ctx context.Context, trainRequest TrainRequest) (result TrainResult, err error) {
635 if tracing.IsEnabled() {
636 ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.TrainCustomModel")
637 defer func() {
638 sc := -1
639 if result.Response.Response != nil {
640 sc = result.Response.Response.StatusCode
641 }
642 tracing.EndSpan(ctx, sc, err)
643 }()
644 }
645 if err := validation.Validate([]validation.Validation{
646 {TargetValue: trainRequest,
647 Constraints: []validation.Constraint{{Target: "trainRequest.Source", Name: validation.Null, Rule: true,
648 Chain: []validation.Constraint{{Target: "trainRequest.Source", Name: validation.MaxLength, Rule: 2048, Chain: nil},
649 {Target: "trainRequest.Source", Name: validation.MinLength, Rule: 0, Chain: nil},
650 }},
651 {Target: "trainRequest.SourceFilter", Name: validation.Null, Rule: false,
652 Chain: []validation.Constraint{{Target: "trainRequest.SourceFilter.Prefix", Name: validation.Null, Rule: false,
653 Chain: []validation.Constraint{{Target: "trainRequest.SourceFilter.Prefix", Name: validation.MaxLength, Rule: 128, Chain: nil},
654 {Target: "trainRequest.SourceFilter.Prefix", Name: validation.MinLength, Rule: 0, Chain: nil},
655 }},
656 }}}}}); err != nil {
657 return result, validation.NewError("formrecognizer.BaseClient", "TrainCustomModel", err.Error())
658 }
659
660 req, err := client.TrainCustomModelPreparer(ctx, trainRequest)
661 if err != nil {
662 err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "TrainCustomModel", nil, "Failure preparing request")
663 return
664 }
665
666 resp, err := client.TrainCustomModelSender(req)
667 if err != nil {
668 result.Response = autorest.Response{Response: resp}
669 err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "TrainCustomModel", resp, "Failure sending request")
670 return
671 }
672
673 result, err = client.TrainCustomModelResponder(resp)
674 if err != nil {
675 err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "TrainCustomModel", resp, "Failure responding to request")
676 return
677 }
678
679 return
680 }
681
682
683 func (client BaseClient) TrainCustomModelPreparer(ctx context.Context, trainRequest TrainRequest) (*http.Request, error) {
684 urlParameters := map[string]interface{}{
685 "Endpoint": client.Endpoint,
686 }
687
688 preparer := autorest.CreatePreparer(
689 autorest.AsContentType("application/json; charset=utf-8"),
690 autorest.AsPost(),
691 autorest.WithCustomBaseURL("{Endpoint}/formrecognizer/v1.0-preview", urlParameters),
692 autorest.WithPath("/custom/train"),
693 autorest.WithJSON(trainRequest))
694 return preparer.Prepare((&http.Request{}).WithContext(ctx))
695 }
696
697
698
699 func (client BaseClient) TrainCustomModelSender(req *http.Request) (*http.Response, error) {
700 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
701 }
702
703
704
705 func (client BaseClient) TrainCustomModelResponder(resp *http.Response) (result TrainResult, err error) {
706 err = autorest.Respond(
707 resp,
708 azure.WithErrorUnlessStatusCode(http.StatusOK),
709 autorest.ByUnmarshallingJSON(&result),
710 autorest.ByClosing())
711 result.Response = autorest.Response{Response: resp}
712 return
713 }
714
View as plain text