1package face 2 3// Copyright (c) Microsoft Corporation. All rights reserved. 4// Licensed under the MIT License. See License.txt in the project root for license information. 5// 6// Code generated by Microsoft (R) AutoRest Code Generator. 7// Changes may cause incorrect behavior and will be lost if the code is regenerated. 8 9import ( 10 "context" 11 "github.com/Azure/go-autorest/autorest" 12 "github.com/Azure/go-autorest/autorest/azure" 13 "github.com/Azure/go-autorest/autorest/validation" 14 "github.com/Azure/go-autorest/tracing" 15 "github.com/gofrs/uuid" 16 "io" 17 "net/http" 18) 19 20// ListClient is the an API for face detection, verification, and identification. 21type ListClient struct { 22 BaseClient 23} 24 25// NewListClient creates an instance of the ListClient client. 26func NewListClient(endpoint string) ListClient { 27 return ListClient{New(endpoint)} 28} 29 30// AddFaceFromStream add a face to a specified face list, up to 1,000 faces. 31// <br /> To deal with an image contains multiple faces, input face can be specified as an image with a targetFace 32// rectangle. It returns a persistedFaceId representing the added face. No image will be stored. Only the extracted 33// face feature will be stored on server until [FaceList - Delete 34// Face](https://docs.microsoft.com/rest/api/cognitiveservices/face/facelist/deleteface) or [FaceList - 35// Delete](https://docs.microsoft.com/rest/api/cognitiveservices/face/facelist/delete) is called. 36// <br /> Note persistedFaceId is different from faceId generated by [Face - 37// Detect](https://docs.microsoft.com/rest/api/cognitiveservices/face/face/detectwithurl). 38// * Higher face image quality means better detection and recognition precision. Please consider high-quality faces: 39// frontal, clear, and face size is 200x200 pixels (100 pixels between eyes) or bigger. 40// * JPEG, PNG, GIF (the first frame), and BMP format are supported. The allowed image file size is from 1KB to 6MB. 41// * "targetFace" rectangle should contain one face. Zero or multiple faces will be regarded as an error. If the 42// provided "targetFace" rectangle is not returned from [Face - 43// Detect](https://docs.microsoft.com/rest/api/cognitiveservices/face/face/detectwithurl), there’s no guarantee to 44// detect and add the face successfully. 45// * Out of detectable face size (36x36 - 4096x4096 pixels), large head-pose, or large occlusions will cause failures. 46// * Adding/deleting faces to/from a same face list are processed sequentially and to/from different face lists are in 47// parallel. 48// * The minimum detectable face size is 36x36 pixels in an image no larger than 1920x1080 pixels. Images with 49// dimensions higher than 1920x1080 pixels will need a proportionally larger minimum face size. 50// * Different 'detectionModel' values can be provided. To use and compare different detection models, please refer to 51// [How to specify a detection 52// model](https://docs.microsoft.com/azure/cognitive-services/face/face-api-how-to-topics/specify-detection-model) 53// | Model | Recommended use-case(s) | 54// | ---------- | -------- | 55// | 'detection_01': | The default detection model for [FaceList - Add 56// Face](https://docs.microsoft.com/rest/api/cognitiveservices/face/facelist/addfacefromurl). Recommend for near 57// frontal face detection. For scenarios with exceptionally large angle (head-pose) faces, occluded faces or wrong 58// image orientation, the faces in such cases may not be detected. | 59// | 'detection_02': | Detection model released in 2019 May with improved accuracy especially on small, side and blurry 60// faces. | 61// Parameters: 62// faceListID - id referencing a particular face list. 63// imageParameter - an image stream. 64// userData - user-specified data about the face for any purpose. The maximum length is 1KB. 65// targetFace - a face rectangle to specify the target face to be added to a person in the format of 66// "targetFace=left,top,width,height". E.g. "targetFace=10,10,100,100". If there is more than one face in the 67// image, targetFace is required to specify which face to add. No targetFace means there is only one face 68// detected in the entire image. 69// detectionModel - name of detection model. Detection model is used to detect faces in the submitted image. A 70// detection model name can be provided when performing Face - Detect or (Large)FaceList - Add Face or 71// (Large)PersonGroup - Add Face. The default value is 'detection_01', if another model is needed, please 72// explicitly specify it. 73func (client ListClient) AddFaceFromStream(ctx context.Context, faceListID string, imageParameter io.ReadCloser, userData string, targetFace []int32, detectionModel DetectionModel) (result PersistedFace, err error) { 74 if tracing.IsEnabled() { 75 ctx = tracing.StartSpan(ctx, fqdn+"/ListClient.AddFaceFromStream") 76 defer func() { 77 sc := -1 78 if result.Response.Response != nil { 79 sc = result.Response.Response.StatusCode 80 } 81 tracing.EndSpan(ctx, sc, err) 82 }() 83 } 84 if err := validation.Validate([]validation.Validation{ 85 {TargetValue: faceListID, 86 Constraints: []validation.Constraint{{Target: "faceListID", Name: validation.MaxLength, Rule: 64, Chain: nil}, 87 {Target: "faceListID", Name: validation.Pattern, Rule: `^[a-z0-9-_]+$`, Chain: nil}}}, 88 {TargetValue: userData, 89 Constraints: []validation.Constraint{{Target: "userData", Name: validation.Empty, Rule: false, 90 Chain: []validation.Constraint{{Target: "userData", Name: validation.MaxLength, Rule: 1024, Chain: nil}}}}}}); err != nil { 91 return result, validation.NewError("face.ListClient", "AddFaceFromStream", err.Error()) 92 } 93 94 req, err := client.AddFaceFromStreamPreparer(ctx, faceListID, imageParameter, userData, targetFace, detectionModel) 95 if err != nil { 96 err = autorest.NewErrorWithError(err, "face.ListClient", "AddFaceFromStream", nil, "Failure preparing request") 97 return 98 } 99 100 resp, err := client.AddFaceFromStreamSender(req) 101 if err != nil { 102 result.Response = autorest.Response{Response: resp} 103 err = autorest.NewErrorWithError(err, "face.ListClient", "AddFaceFromStream", resp, "Failure sending request") 104 return 105 } 106 107 result, err = client.AddFaceFromStreamResponder(resp) 108 if err != nil { 109 err = autorest.NewErrorWithError(err, "face.ListClient", "AddFaceFromStream", resp, "Failure responding to request") 110 return 111 } 112 113 return 114} 115 116// AddFaceFromStreamPreparer prepares the AddFaceFromStream request. 117func (client ListClient) AddFaceFromStreamPreparer(ctx context.Context, faceListID string, imageParameter io.ReadCloser, userData string, targetFace []int32, detectionModel DetectionModel) (*http.Request, error) { 118 urlParameters := map[string]interface{}{ 119 "Endpoint": client.Endpoint, 120 } 121 122 pathParameters := map[string]interface{}{ 123 "faceListId": autorest.Encode("path", faceListID), 124 } 125 126 queryParameters := map[string]interface{}{} 127 if len(userData) > 0 { 128 queryParameters["userData"] = autorest.Encode("query", userData) 129 } 130 if targetFace != nil && len(targetFace) > 0 { 131 queryParameters["targetFace"] = autorest.Encode("query", targetFace, ",") 132 } 133 if len(string(detectionModel)) > 0 { 134 queryParameters["detectionModel"] = autorest.Encode("query", detectionModel) 135 } else { 136 queryParameters["detectionModel"] = autorest.Encode("query", "detection_01") 137 } 138 139 preparer := autorest.CreatePreparer( 140 autorest.AsContentType("application/octet-stream"), 141 autorest.AsPost(), 142 autorest.WithCustomBaseURL("{Endpoint}/face/v1.0", urlParameters), 143 autorest.WithPathParameters("/facelists/{faceListId}/persistedfaces", pathParameters), 144 autorest.WithFile(imageParameter), 145 autorest.WithQueryParameters(queryParameters)) 146 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 147} 148 149// AddFaceFromStreamSender sends the AddFaceFromStream request. The method will close the 150// http.Response Body if it receives an error. 151func (client ListClient) AddFaceFromStreamSender(req *http.Request) (*http.Response, error) { 152 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 153} 154 155// AddFaceFromStreamResponder handles the response to the AddFaceFromStream request. The method always 156// closes the http.Response Body. 157func (client ListClient) AddFaceFromStreamResponder(resp *http.Response) (result PersistedFace, err error) { 158 err = autorest.Respond( 159 resp, 160 azure.WithErrorUnlessStatusCode(http.StatusOK), 161 autorest.ByUnmarshallingJSON(&result), 162 autorest.ByClosing()) 163 result.Response = autorest.Response{Response: resp} 164 return 165} 166 167// AddFaceFromURL add a face to a specified face list, up to 1,000 faces. 168// <br /> To deal with an image contains multiple faces, input face can be specified as an image with a targetFace 169// rectangle. It returns a persistedFaceId representing the added face. No image will be stored. Only the extracted 170// face feature will be stored on server until [FaceList - Delete 171// Face](https://docs.microsoft.com/rest/api/cognitiveservices/face/facelist/deleteface) or [FaceList - 172// Delete](https://docs.microsoft.com/rest/api/cognitiveservices/face/facelist/delete) is called. 173// <br /> Note persistedFaceId is different from faceId generated by [Face - 174// Detect](https://docs.microsoft.com/rest/api/cognitiveservices/face/face/detectwithurl). 175// * Higher face image quality means better detection and recognition precision. Please consider high-quality faces: 176// frontal, clear, and face size is 200x200 pixels (100 pixels between eyes) or bigger. 177// * JPEG, PNG, GIF (the first frame), and BMP format are supported. The allowed image file size is from 1KB to 6MB. 178// * "targetFace" rectangle should contain one face. Zero or multiple faces will be regarded as an error. If the 179// provided "targetFace" rectangle is not returned from [Face - 180// Detect](https://docs.microsoft.com/rest/api/cognitiveservices/face/face/detectwithurl), there’s no guarantee to 181// detect and add the face successfully. 182// * Out of detectable face size (36x36 - 4096x4096 pixels), large head-pose, or large occlusions will cause failures. 183// * Adding/deleting faces to/from a same face list are processed sequentially and to/from different face lists are in 184// parallel. 185// * The minimum detectable face size is 36x36 pixels in an image no larger than 1920x1080 pixels. Images with 186// dimensions higher than 1920x1080 pixels will need a proportionally larger minimum face size. 187// * Different 'detectionModel' values can be provided. To use and compare different detection models, please refer to 188// [How to specify a detection 189// model](https://docs.microsoft.com/azure/cognitive-services/face/face-api-how-to-topics/specify-detection-model) 190// | Model | Recommended use-case(s) | 191// | ---------- | -------- | 192// | 'detection_01': | The default detection model for [FaceList - Add 193// Face](https://docs.microsoft.com/rest/api/cognitiveservices/face/facelist/addfacefromurl). Recommend for near 194// frontal face detection. For scenarios with exceptionally large angle (head-pose) faces, occluded faces or wrong 195// image orientation, the faces in such cases may not be detected. | 196// | 'detection_02': | Detection model released in 2019 May with improved accuracy especially on small, side and blurry 197// faces. | 198// Parameters: 199// faceListID - id referencing a particular face list. 200// imageURL - a JSON document with a URL pointing to the image that is to be analyzed. 201// userData - user-specified data about the face for any purpose. The maximum length is 1KB. 202// targetFace - a face rectangle to specify the target face to be added to a person in the format of 203// "targetFace=left,top,width,height". E.g. "targetFace=10,10,100,100". If there is more than one face in the 204// image, targetFace is required to specify which face to add. No targetFace means there is only one face 205// detected in the entire image. 206// detectionModel - name of detection model. Detection model is used to detect faces in the submitted image. A 207// detection model name can be provided when performing Face - Detect or (Large)FaceList - Add Face or 208// (Large)PersonGroup - Add Face. The default value is 'detection_01', if another model is needed, please 209// explicitly specify it. 210func (client ListClient) AddFaceFromURL(ctx context.Context, faceListID string, imageURL ImageURL, userData string, targetFace []int32, detectionModel DetectionModel) (result PersistedFace, err error) { 211 if tracing.IsEnabled() { 212 ctx = tracing.StartSpan(ctx, fqdn+"/ListClient.AddFaceFromURL") 213 defer func() { 214 sc := -1 215 if result.Response.Response != nil { 216 sc = result.Response.Response.StatusCode 217 } 218 tracing.EndSpan(ctx, sc, err) 219 }() 220 } 221 if err := validation.Validate([]validation.Validation{ 222 {TargetValue: faceListID, 223 Constraints: []validation.Constraint{{Target: "faceListID", Name: validation.MaxLength, Rule: 64, Chain: nil}, 224 {Target: "faceListID", Name: validation.Pattern, Rule: `^[a-z0-9-_]+$`, Chain: nil}}}, 225 {TargetValue: userData, 226 Constraints: []validation.Constraint{{Target: "userData", Name: validation.Empty, Rule: false, 227 Chain: []validation.Constraint{{Target: "userData", Name: validation.MaxLength, Rule: 1024, Chain: nil}}}}}, 228 {TargetValue: imageURL, 229 Constraints: []validation.Constraint{{Target: "imageURL.URL", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { 230 return result, validation.NewError("face.ListClient", "AddFaceFromURL", err.Error()) 231 } 232 233 req, err := client.AddFaceFromURLPreparer(ctx, faceListID, imageURL, userData, targetFace, detectionModel) 234 if err != nil { 235 err = autorest.NewErrorWithError(err, "face.ListClient", "AddFaceFromURL", nil, "Failure preparing request") 236 return 237 } 238 239 resp, err := client.AddFaceFromURLSender(req) 240 if err != nil { 241 result.Response = autorest.Response{Response: resp} 242 err = autorest.NewErrorWithError(err, "face.ListClient", "AddFaceFromURL", resp, "Failure sending request") 243 return 244 } 245 246 result, err = client.AddFaceFromURLResponder(resp) 247 if err != nil { 248 err = autorest.NewErrorWithError(err, "face.ListClient", "AddFaceFromURL", resp, "Failure responding to request") 249 return 250 } 251 252 return 253} 254 255// AddFaceFromURLPreparer prepares the AddFaceFromURL request. 256func (client ListClient) AddFaceFromURLPreparer(ctx context.Context, faceListID string, imageURL ImageURL, userData string, targetFace []int32, detectionModel DetectionModel) (*http.Request, error) { 257 urlParameters := map[string]interface{}{ 258 "Endpoint": client.Endpoint, 259 } 260 261 pathParameters := map[string]interface{}{ 262 "faceListId": autorest.Encode("path", faceListID), 263 } 264 265 queryParameters := map[string]interface{}{} 266 if len(userData) > 0 { 267 queryParameters["userData"] = autorest.Encode("query", userData) 268 } 269 if targetFace != nil && len(targetFace) > 0 { 270 queryParameters["targetFace"] = autorest.Encode("query", targetFace, ",") 271 } 272 if len(string(detectionModel)) > 0 { 273 queryParameters["detectionModel"] = autorest.Encode("query", detectionModel) 274 } else { 275 queryParameters["detectionModel"] = autorest.Encode("query", "detection_01") 276 } 277 278 preparer := autorest.CreatePreparer( 279 autorest.AsContentType("application/json; charset=utf-8"), 280 autorest.AsPost(), 281 autorest.WithCustomBaseURL("{Endpoint}/face/v1.0", urlParameters), 282 autorest.WithPathParameters("/facelists/{faceListId}/persistedfaces", pathParameters), 283 autorest.WithJSON(imageURL), 284 autorest.WithQueryParameters(queryParameters)) 285 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 286} 287 288// AddFaceFromURLSender sends the AddFaceFromURL request. The method will close the 289// http.Response Body if it receives an error. 290func (client ListClient) AddFaceFromURLSender(req *http.Request) (*http.Response, error) { 291 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 292} 293 294// AddFaceFromURLResponder handles the response to the AddFaceFromURL request. The method always 295// closes the http.Response Body. 296func (client ListClient) AddFaceFromURLResponder(resp *http.Response) (result PersistedFace, err error) { 297 err = autorest.Respond( 298 resp, 299 azure.WithErrorUnlessStatusCode(http.StatusOK), 300 autorest.ByUnmarshallingJSON(&result), 301 autorest.ByClosing()) 302 result.Response = autorest.Response{Response: resp} 303 return 304} 305 306// Create create an empty face list with user-specified faceListId, name, an optional userData and recognitionModel. Up 307// to 64 face lists are allowed in one subscription. 308// <br /> Face list is a list of faces, up to 1,000 faces, and used by [Face - Find 309// Similar](https://docs.microsoft.com/rest/api/cognitiveservices/face/face/findsimilar). 310// <br /> After creation, user should use [FaceList - Add 311// Face](https://docs.microsoft.com/rest/api/cognitiveservices/face/facelist/addfacefromurl) to import the faces. No 312// image will be stored. Only the extracted face features are stored on server until [FaceList - 313// Delete](https://docs.microsoft.com/rest/api/cognitiveservices/face/facelist/delete) is called. 314// <br /> Find Similar is used for scenario like finding celebrity-like faces, similar face filtering, or as a light 315// way face identification. But if the actual use is to identify person, please use 316// [PersonGroup](https://docs.microsoft.com/rest/api/cognitiveservices/face/persongroup) / 317// [LargePersonGroup](https://docs.microsoft.com/rest/api/cognitiveservices/face/largepersongroup) and [Face - 318// Identify](https://docs.microsoft.com/rest/api/cognitiveservices/face/face/identify). 319// <br /> Please consider [LargeFaceList](https://docs.microsoft.com/rest/api/cognitiveservices/face/largefacelist) 320// when the face number is large. It can support up to 1,000,000 faces. 321// <br />'recognitionModel' should be specified to associate with this face list. The default value for 322// 'recognitionModel' is 'recognition_01', if the latest model needed, please explicitly specify the model you need in 323// this parameter. New faces that are added to an existing face list will use the recognition model that's already 324// associated with the collection. Existing face features in a face list can't be updated to features extracted by 325// another version of recognition model. 326// * 'recognition_01': The default recognition model for [FaceList- 327// Create](https://docs.microsoft.com/rest/api/cognitiveservices/face/facelist/create). All those face lists created 328// before 2019 March are bonded with this recognition model. 329// * 'recognition_02': Recognition model released in 2019 March. 330// * 'recognition_03': Recognition model released in 2020 May. 'recognition_03' is recommended since its overall 331// accuracy is improved compared with 'recognition_01' and 'recognition_02'. 332// Parameters: 333// faceListID - id referencing a particular face list. 334// body - request body for creating a face list. 335func (client ListClient) Create(ctx context.Context, faceListID string, body MetaDataContract) (result autorest.Response, err error) { 336 if tracing.IsEnabled() { 337 ctx = tracing.StartSpan(ctx, fqdn+"/ListClient.Create") 338 defer func() { 339 sc := -1 340 if result.Response != nil { 341 sc = result.Response.StatusCode 342 } 343 tracing.EndSpan(ctx, sc, err) 344 }() 345 } 346 if err := validation.Validate([]validation.Validation{ 347 {TargetValue: faceListID, 348 Constraints: []validation.Constraint{{Target: "faceListID", Name: validation.MaxLength, Rule: 64, Chain: nil}, 349 {Target: "faceListID", Name: validation.Pattern, Rule: `^[a-z0-9-_]+$`, Chain: nil}}}}); err != nil { 350 return result, validation.NewError("face.ListClient", "Create", err.Error()) 351 } 352 353 req, err := client.CreatePreparer(ctx, faceListID, body) 354 if err != nil { 355 err = autorest.NewErrorWithError(err, "face.ListClient", "Create", nil, "Failure preparing request") 356 return 357 } 358 359 resp, err := client.CreateSender(req) 360 if err != nil { 361 result.Response = resp 362 err = autorest.NewErrorWithError(err, "face.ListClient", "Create", resp, "Failure sending request") 363 return 364 } 365 366 result, err = client.CreateResponder(resp) 367 if err != nil { 368 err = autorest.NewErrorWithError(err, "face.ListClient", "Create", resp, "Failure responding to request") 369 return 370 } 371 372 return 373} 374 375// CreatePreparer prepares the Create request. 376func (client ListClient) CreatePreparer(ctx context.Context, faceListID string, body MetaDataContract) (*http.Request, error) { 377 urlParameters := map[string]interface{}{ 378 "Endpoint": client.Endpoint, 379 } 380 381 pathParameters := map[string]interface{}{ 382 "faceListId": autorest.Encode("path", faceListID), 383 } 384 385 preparer := autorest.CreatePreparer( 386 autorest.AsContentType("application/json; charset=utf-8"), 387 autorest.AsPut(), 388 autorest.WithCustomBaseURL("{Endpoint}/face/v1.0", urlParameters), 389 autorest.WithPathParameters("/facelists/{faceListId}", pathParameters), 390 autorest.WithJSON(body)) 391 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 392} 393 394// CreateSender sends the Create request. The method will close the 395// http.Response Body if it receives an error. 396func (client ListClient) CreateSender(req *http.Request) (*http.Response, error) { 397 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 398} 399 400// CreateResponder handles the response to the Create request. The method always 401// closes the http.Response Body. 402func (client ListClient) CreateResponder(resp *http.Response) (result autorest.Response, err error) { 403 err = autorest.Respond( 404 resp, 405 azure.WithErrorUnlessStatusCode(http.StatusOK), 406 autorest.ByClosing()) 407 result.Response = resp 408 return 409} 410 411// Delete delete a specified face list. 412// Parameters: 413// faceListID - id referencing a particular face list. 414func (client ListClient) Delete(ctx context.Context, faceListID string) (result autorest.Response, err error) { 415 if tracing.IsEnabled() { 416 ctx = tracing.StartSpan(ctx, fqdn+"/ListClient.Delete") 417 defer func() { 418 sc := -1 419 if result.Response != nil { 420 sc = result.Response.StatusCode 421 } 422 tracing.EndSpan(ctx, sc, err) 423 }() 424 } 425 if err := validation.Validate([]validation.Validation{ 426 {TargetValue: faceListID, 427 Constraints: []validation.Constraint{{Target: "faceListID", Name: validation.MaxLength, Rule: 64, Chain: nil}, 428 {Target: "faceListID", Name: validation.Pattern, Rule: `^[a-z0-9-_]+$`, Chain: nil}}}}); err != nil { 429 return result, validation.NewError("face.ListClient", "Delete", err.Error()) 430 } 431 432 req, err := client.DeletePreparer(ctx, faceListID) 433 if err != nil { 434 err = autorest.NewErrorWithError(err, "face.ListClient", "Delete", nil, "Failure preparing request") 435 return 436 } 437 438 resp, err := client.DeleteSender(req) 439 if err != nil { 440 result.Response = resp 441 err = autorest.NewErrorWithError(err, "face.ListClient", "Delete", resp, "Failure sending request") 442 return 443 } 444 445 result, err = client.DeleteResponder(resp) 446 if err != nil { 447 err = autorest.NewErrorWithError(err, "face.ListClient", "Delete", resp, "Failure responding to request") 448 return 449 } 450 451 return 452} 453 454// DeletePreparer prepares the Delete request. 455func (client ListClient) DeletePreparer(ctx context.Context, faceListID string) (*http.Request, error) { 456 urlParameters := map[string]interface{}{ 457 "Endpoint": client.Endpoint, 458 } 459 460 pathParameters := map[string]interface{}{ 461 "faceListId": autorest.Encode("path", faceListID), 462 } 463 464 preparer := autorest.CreatePreparer( 465 autorest.AsDelete(), 466 autorest.WithCustomBaseURL("{Endpoint}/face/v1.0", urlParameters), 467 autorest.WithPathParameters("/facelists/{faceListId}", pathParameters)) 468 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 469} 470 471// DeleteSender sends the Delete request. The method will close the 472// http.Response Body if it receives an error. 473func (client ListClient) DeleteSender(req *http.Request) (*http.Response, error) { 474 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 475} 476 477// DeleteResponder handles the response to the Delete request. The method always 478// closes the http.Response Body. 479func (client ListClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 480 err = autorest.Respond( 481 resp, 482 azure.WithErrorUnlessStatusCode(http.StatusOK), 483 autorest.ByClosing()) 484 result.Response = resp 485 return 486} 487 488// DeleteFace delete a face from a face list by specified faceListId and persistedFaceId. 489// <br /> Adding/deleting faces to/from a same face list are processed sequentially and to/from different face lists 490// are in parallel. 491// Parameters: 492// faceListID - id referencing a particular face list. 493// persistedFaceID - id referencing a particular persistedFaceId of an existing face. 494func (client ListClient) DeleteFace(ctx context.Context, faceListID string, persistedFaceID uuid.UUID) (result autorest.Response, err error) { 495 if tracing.IsEnabled() { 496 ctx = tracing.StartSpan(ctx, fqdn+"/ListClient.DeleteFace") 497 defer func() { 498 sc := -1 499 if result.Response != nil { 500 sc = result.Response.StatusCode 501 } 502 tracing.EndSpan(ctx, sc, err) 503 }() 504 } 505 if err := validation.Validate([]validation.Validation{ 506 {TargetValue: faceListID, 507 Constraints: []validation.Constraint{{Target: "faceListID", Name: validation.MaxLength, Rule: 64, Chain: nil}, 508 {Target: "faceListID", Name: validation.Pattern, Rule: `^[a-z0-9-_]+$`, Chain: nil}}}}); err != nil { 509 return result, validation.NewError("face.ListClient", "DeleteFace", err.Error()) 510 } 511 512 req, err := client.DeleteFacePreparer(ctx, faceListID, persistedFaceID) 513 if err != nil { 514 err = autorest.NewErrorWithError(err, "face.ListClient", "DeleteFace", nil, "Failure preparing request") 515 return 516 } 517 518 resp, err := client.DeleteFaceSender(req) 519 if err != nil { 520 result.Response = resp 521 err = autorest.NewErrorWithError(err, "face.ListClient", "DeleteFace", resp, "Failure sending request") 522 return 523 } 524 525 result, err = client.DeleteFaceResponder(resp) 526 if err != nil { 527 err = autorest.NewErrorWithError(err, "face.ListClient", "DeleteFace", resp, "Failure responding to request") 528 return 529 } 530 531 return 532} 533 534// DeleteFacePreparer prepares the DeleteFace request. 535func (client ListClient) DeleteFacePreparer(ctx context.Context, faceListID string, persistedFaceID uuid.UUID) (*http.Request, error) { 536 urlParameters := map[string]interface{}{ 537 "Endpoint": client.Endpoint, 538 } 539 540 pathParameters := map[string]interface{}{ 541 "faceListId": autorest.Encode("path", faceListID), 542 "persistedFaceId": autorest.Encode("path", persistedFaceID), 543 } 544 545 preparer := autorest.CreatePreparer( 546 autorest.AsDelete(), 547 autorest.WithCustomBaseURL("{Endpoint}/face/v1.0", urlParameters), 548 autorest.WithPathParameters("/facelists/{faceListId}/persistedfaces/{persistedFaceId}", pathParameters)) 549 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 550} 551 552// DeleteFaceSender sends the DeleteFace request. The method will close the 553// http.Response Body if it receives an error. 554func (client ListClient) DeleteFaceSender(req *http.Request) (*http.Response, error) { 555 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 556} 557 558// DeleteFaceResponder handles the response to the DeleteFace request. The method always 559// closes the http.Response Body. 560func (client ListClient) DeleteFaceResponder(resp *http.Response) (result autorest.Response, err error) { 561 err = autorest.Respond( 562 resp, 563 azure.WithErrorUnlessStatusCode(http.StatusOK), 564 autorest.ByClosing()) 565 result.Response = resp 566 return 567} 568 569// Get retrieve a face list’s faceListId, name, userData, recognitionModel and faces in the face list. 570// Parameters: 571// faceListID - id referencing a particular face list. 572// returnRecognitionModel - a value indicating whether the operation should return 'recognitionModel' in 573// response. 574func (client ListClient) Get(ctx context.Context, faceListID string, returnRecognitionModel *bool) (result List, err error) { 575 if tracing.IsEnabled() { 576 ctx = tracing.StartSpan(ctx, fqdn+"/ListClient.Get") 577 defer func() { 578 sc := -1 579 if result.Response.Response != nil { 580 sc = result.Response.Response.StatusCode 581 } 582 tracing.EndSpan(ctx, sc, err) 583 }() 584 } 585 if err := validation.Validate([]validation.Validation{ 586 {TargetValue: faceListID, 587 Constraints: []validation.Constraint{{Target: "faceListID", Name: validation.MaxLength, Rule: 64, Chain: nil}, 588 {Target: "faceListID", Name: validation.Pattern, Rule: `^[a-z0-9-_]+$`, Chain: nil}}}}); err != nil { 589 return result, validation.NewError("face.ListClient", "Get", err.Error()) 590 } 591 592 req, err := client.GetPreparer(ctx, faceListID, returnRecognitionModel) 593 if err != nil { 594 err = autorest.NewErrorWithError(err, "face.ListClient", "Get", nil, "Failure preparing request") 595 return 596 } 597 598 resp, err := client.GetSender(req) 599 if err != nil { 600 result.Response = autorest.Response{Response: resp} 601 err = autorest.NewErrorWithError(err, "face.ListClient", "Get", resp, "Failure sending request") 602 return 603 } 604 605 result, err = client.GetResponder(resp) 606 if err != nil { 607 err = autorest.NewErrorWithError(err, "face.ListClient", "Get", resp, "Failure responding to request") 608 return 609 } 610 611 return 612} 613 614// GetPreparer prepares the Get request. 615func (client ListClient) GetPreparer(ctx context.Context, faceListID string, returnRecognitionModel *bool) (*http.Request, error) { 616 urlParameters := map[string]interface{}{ 617 "Endpoint": client.Endpoint, 618 } 619 620 pathParameters := map[string]interface{}{ 621 "faceListId": autorest.Encode("path", faceListID), 622 } 623 624 queryParameters := map[string]interface{}{} 625 if returnRecognitionModel != nil { 626 queryParameters["returnRecognitionModel"] = autorest.Encode("query", *returnRecognitionModel) 627 } else { 628 queryParameters["returnRecognitionModel"] = autorest.Encode("query", false) 629 } 630 631 preparer := autorest.CreatePreparer( 632 autorest.AsGet(), 633 autorest.WithCustomBaseURL("{Endpoint}/face/v1.0", urlParameters), 634 autorest.WithPathParameters("/facelists/{faceListId}", pathParameters), 635 autorest.WithQueryParameters(queryParameters)) 636 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 637} 638 639// GetSender sends the Get request. The method will close the 640// http.Response Body if it receives an error. 641func (client ListClient) GetSender(req *http.Request) (*http.Response, error) { 642 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 643} 644 645// GetResponder handles the response to the Get request. The method always 646// closes the http.Response Body. 647func (client ListClient) GetResponder(resp *http.Response) (result List, err error) { 648 err = autorest.Respond( 649 resp, 650 azure.WithErrorUnlessStatusCode(http.StatusOK), 651 autorest.ByUnmarshallingJSON(&result), 652 autorest.ByClosing()) 653 result.Response = autorest.Response{Response: resp} 654 return 655} 656 657// List list face lists’ faceListId, name, userData and recognitionModel. <br /> 658// To get face information inside faceList use [FaceList - 659// Get](https://docs.microsoft.com/rest/api/cognitiveservices/face/facelist/get) 660// Parameters: 661// returnRecognitionModel - a value indicating whether the operation should return 'recognitionModel' in 662// response. 663func (client ListClient) List(ctx context.Context, returnRecognitionModel *bool) (result ListList, err error) { 664 if tracing.IsEnabled() { 665 ctx = tracing.StartSpan(ctx, fqdn+"/ListClient.List") 666 defer func() { 667 sc := -1 668 if result.Response.Response != nil { 669 sc = result.Response.Response.StatusCode 670 } 671 tracing.EndSpan(ctx, sc, err) 672 }() 673 } 674 req, err := client.ListPreparer(ctx, returnRecognitionModel) 675 if err != nil { 676 err = autorest.NewErrorWithError(err, "face.ListClient", "List", nil, "Failure preparing request") 677 return 678 } 679 680 resp, err := client.ListSender(req) 681 if err != nil { 682 result.Response = autorest.Response{Response: resp} 683 err = autorest.NewErrorWithError(err, "face.ListClient", "List", resp, "Failure sending request") 684 return 685 } 686 687 result, err = client.ListResponder(resp) 688 if err != nil { 689 err = autorest.NewErrorWithError(err, "face.ListClient", "List", resp, "Failure responding to request") 690 return 691 } 692 693 return 694} 695 696// ListPreparer prepares the List request. 697func (client ListClient) ListPreparer(ctx context.Context, returnRecognitionModel *bool) (*http.Request, error) { 698 urlParameters := map[string]interface{}{ 699 "Endpoint": client.Endpoint, 700 } 701 702 queryParameters := map[string]interface{}{} 703 if returnRecognitionModel != nil { 704 queryParameters["returnRecognitionModel"] = autorest.Encode("query", *returnRecognitionModel) 705 } else { 706 queryParameters["returnRecognitionModel"] = autorest.Encode("query", false) 707 } 708 709 preparer := autorest.CreatePreparer( 710 autorest.AsGet(), 711 autorest.WithCustomBaseURL("{Endpoint}/face/v1.0", urlParameters), 712 autorest.WithPath("/facelists"), 713 autorest.WithQueryParameters(queryParameters)) 714 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 715} 716 717// ListSender sends the List request. The method will close the 718// http.Response Body if it receives an error. 719func (client ListClient) ListSender(req *http.Request) (*http.Response, error) { 720 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 721} 722 723// ListResponder handles the response to the List request. The method always 724// closes the http.Response Body. 725func (client ListClient) ListResponder(resp *http.Response) (result ListList, err error) { 726 err = autorest.Respond( 727 resp, 728 azure.WithErrorUnlessStatusCode(http.StatusOK), 729 autorest.ByUnmarshallingJSON(&result.Value), 730 autorest.ByClosing()) 731 result.Response = autorest.Response{Response: resp} 732 return 733} 734 735// Update update information of a face list. 736// Parameters: 737// faceListID - id referencing a particular face list. 738// body - request body for updating a face list. 739func (client ListClient) Update(ctx context.Context, faceListID string, body NameAndUserDataContract) (result autorest.Response, err error) { 740 if tracing.IsEnabled() { 741 ctx = tracing.StartSpan(ctx, fqdn+"/ListClient.Update") 742 defer func() { 743 sc := -1 744 if result.Response != nil { 745 sc = result.Response.StatusCode 746 } 747 tracing.EndSpan(ctx, sc, err) 748 }() 749 } 750 if err := validation.Validate([]validation.Validation{ 751 {TargetValue: faceListID, 752 Constraints: []validation.Constraint{{Target: "faceListID", Name: validation.MaxLength, Rule: 64, Chain: nil}, 753 {Target: "faceListID", Name: validation.Pattern, Rule: `^[a-z0-9-_]+$`, Chain: nil}}}}); err != nil { 754 return result, validation.NewError("face.ListClient", "Update", err.Error()) 755 } 756 757 req, err := client.UpdatePreparer(ctx, faceListID, body) 758 if err != nil { 759 err = autorest.NewErrorWithError(err, "face.ListClient", "Update", nil, "Failure preparing request") 760 return 761 } 762 763 resp, err := client.UpdateSender(req) 764 if err != nil { 765 result.Response = resp 766 err = autorest.NewErrorWithError(err, "face.ListClient", "Update", resp, "Failure sending request") 767 return 768 } 769 770 result, err = client.UpdateResponder(resp) 771 if err != nil { 772 err = autorest.NewErrorWithError(err, "face.ListClient", "Update", resp, "Failure responding to request") 773 return 774 } 775 776 return 777} 778 779// UpdatePreparer prepares the Update request. 780func (client ListClient) UpdatePreparer(ctx context.Context, faceListID string, body NameAndUserDataContract) (*http.Request, error) { 781 urlParameters := map[string]interface{}{ 782 "Endpoint": client.Endpoint, 783 } 784 785 pathParameters := map[string]interface{}{ 786 "faceListId": autorest.Encode("path", faceListID), 787 } 788 789 preparer := autorest.CreatePreparer( 790 autorest.AsContentType("application/json; charset=utf-8"), 791 autorest.AsPatch(), 792 autorest.WithCustomBaseURL("{Endpoint}/face/v1.0", urlParameters), 793 autorest.WithPathParameters("/facelists/{faceListId}", pathParameters), 794 autorest.WithJSON(body)) 795 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 796} 797 798// UpdateSender sends the Update request. The method will close the 799// http.Response Body if it receives an error. 800func (client ListClient) UpdateSender(req *http.Request) (*http.Response, error) { 801 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 802} 803 804// UpdateResponder handles the response to the Update request. The method always 805// closes the http.Response Body. 806func (client ListClient) UpdateResponder(resp *http.Response) (result autorest.Response, err error) { 807 err = autorest.Respond( 808 resp, 809 azure.WithErrorUnlessStatusCode(http.StatusOK), 810 autorest.ByClosing()) 811 result.Response = resp 812 return 813} 814