...

Source file src/github.com/Azure/azure-sdk-for-go/services/cognitiveservices/v1.0/face/persongroup.go

Documentation: github.com/Azure/azure-sdk-for-go/services/cognitiveservices/v1.0/face

     1  package 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  
     9  import (
    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  	"net/http"
    16  )
    17  
    18  // PersonGroupClient is the an API for face detection, verification, and identification.
    19  type PersonGroupClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewPersonGroupClient creates an instance of the PersonGroupClient client.
    24  func NewPersonGroupClient(endpoint string) PersonGroupClient {
    25  	return PersonGroupClient{New(endpoint)}
    26  }
    27  
    28  // Create create a new person group with specified personGroupId, name, user-provided userData and recognitionModel.
    29  // <br /> A person group is the container of the uploaded person data, including face recognition features.
    30  // <br /> After creation, use [PersonGroup Person -
    31  // Create](https://docs.microsoft.com/rest/api/cognitiveservices/face/persongroupperson/create) to add persons into the
    32  // group, and then call [PersonGroup -
    33  // Train](https://docs.microsoft.com/rest/api/cognitiveservices/face/persongroup/train) to get this group ready for
    34  // [Face - Identify](https://docs.microsoft.com/rest/api/cognitiveservices/face/face/identify).
    35  // <br /> No image will be stored. Only the person's extracted face features and userData will be stored on server
    36  // until [PersonGroup Person -
    37  // Delete](https://docs.microsoft.com/rest/api/cognitiveservices/face/persongroupperson/delete) or [PersonGroup -
    38  // Delete](https://docs.microsoft.com/rest/api/cognitiveservices/face/persongroup/delete) is called.
    39  // <br/>'recognitionModel' should be specified to associate with this person group. The default value for
    40  // 'recognitionModel' is 'recognition_01', if the latest model needed, please explicitly specify the model you need in
    41  // this parameter. New faces that are added to an existing person group will use the recognition model that's already
    42  // associated with the collection. Existing face features in a person group can't be updated to features extracted by
    43  // another version of recognition model.
    44  // * 'recognition_01': The default recognition model for [PersonGroup -
    45  // Create](https://docs.microsoft.com/rest/api/cognitiveservices/face/persongroup/create). All those person groups
    46  // created before 2019 March are bonded with this recognition model.
    47  // * 'recognition_02': Recognition model released in 2019 March.
    48  // * 'recognition_03': Recognition model released in 2020 May. 'recognition_03' is recommended since its overall
    49  // accuracy is improved compared with 'recognition_01' and 'recognition_02'.
    50  //
    51  // Person group quota:
    52  // * Free-tier subscription quota: 1,000 person groups. Each holds up to 1,000 persons.
    53  // * S0-tier subscription quota: 1,000,000 person groups. Each holds up to 10,000 persons.
    54  // * to handle larger scale face identification problem, please consider using
    55  // [LargePersonGroup](https://docs.microsoft.com/rest/api/cognitiveservices/face/largepersongroup).
    56  // Parameters:
    57  // personGroupID - id referencing a particular person group.
    58  // body - request body for creating new person group.
    59  func (client PersonGroupClient) Create(ctx context.Context, personGroupID string, body MetaDataContract) (result autorest.Response, err error) {
    60  	if tracing.IsEnabled() {
    61  		ctx = tracing.StartSpan(ctx, fqdn+"/PersonGroupClient.Create")
    62  		defer func() {
    63  			sc := -1
    64  			if result.Response != nil {
    65  				sc = result.Response.StatusCode
    66  			}
    67  			tracing.EndSpan(ctx, sc, err)
    68  		}()
    69  	}
    70  	if err := validation.Validate([]validation.Validation{
    71  		{TargetValue: personGroupID,
    72  			Constraints: []validation.Constraint{{Target: "personGroupID", Name: validation.MaxLength, Rule: 64, Chain: nil},
    73  				{Target: "personGroupID", Name: validation.Pattern, Rule: `^[a-z0-9-_]+$`, Chain: nil}}}}); err != nil {
    74  		return result, validation.NewError("face.PersonGroupClient", "Create", err.Error())
    75  	}
    76  
    77  	req, err := client.CreatePreparer(ctx, personGroupID, body)
    78  	if err != nil {
    79  		err = autorest.NewErrorWithError(err, "face.PersonGroupClient", "Create", nil, "Failure preparing request")
    80  		return
    81  	}
    82  
    83  	resp, err := client.CreateSender(req)
    84  	if err != nil {
    85  		result.Response = resp
    86  		err = autorest.NewErrorWithError(err, "face.PersonGroupClient", "Create", resp, "Failure sending request")
    87  		return
    88  	}
    89  
    90  	result, err = client.CreateResponder(resp)
    91  	if err != nil {
    92  		err = autorest.NewErrorWithError(err, "face.PersonGroupClient", "Create", resp, "Failure responding to request")
    93  		return
    94  	}
    95  
    96  	return
    97  }
    98  
    99  // CreatePreparer prepares the Create request.
   100  func (client PersonGroupClient) CreatePreparer(ctx context.Context, personGroupID string, body MetaDataContract) (*http.Request, error) {
   101  	urlParameters := map[string]interface{}{
   102  		"Endpoint": client.Endpoint,
   103  	}
   104  
   105  	pathParameters := map[string]interface{}{
   106  		"personGroupId": autorest.Encode("path", personGroupID),
   107  	}
   108  
   109  	preparer := autorest.CreatePreparer(
   110  		autorest.AsContentType("application/json; charset=utf-8"),
   111  		autorest.AsPut(),
   112  		autorest.WithCustomBaseURL("{Endpoint}/face/v1.0", urlParameters),
   113  		autorest.WithPathParameters("/persongroups/{personGroupId}", pathParameters),
   114  		autorest.WithJSON(body))
   115  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   116  }
   117  
   118  // CreateSender sends the Create request. The method will close the
   119  // http.Response Body if it receives an error.
   120  func (client PersonGroupClient) CreateSender(req *http.Request) (*http.Response, error) {
   121  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   122  }
   123  
   124  // CreateResponder handles the response to the Create request. The method always
   125  // closes the http.Response Body.
   126  func (client PersonGroupClient) CreateResponder(resp *http.Response) (result autorest.Response, err error) {
   127  	err = autorest.Respond(
   128  		resp,
   129  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   130  		autorest.ByClosing())
   131  	result.Response = resp
   132  	return
   133  }
   134  
   135  // Delete delete an existing person group. Persisted face features of all people in the person group will also be
   136  // deleted.
   137  // Parameters:
   138  // personGroupID - id referencing a particular person group.
   139  func (client PersonGroupClient) Delete(ctx context.Context, personGroupID string) (result autorest.Response, err error) {
   140  	if tracing.IsEnabled() {
   141  		ctx = tracing.StartSpan(ctx, fqdn+"/PersonGroupClient.Delete")
   142  		defer func() {
   143  			sc := -1
   144  			if result.Response != nil {
   145  				sc = result.Response.StatusCode
   146  			}
   147  			tracing.EndSpan(ctx, sc, err)
   148  		}()
   149  	}
   150  	if err := validation.Validate([]validation.Validation{
   151  		{TargetValue: personGroupID,
   152  			Constraints: []validation.Constraint{{Target: "personGroupID", Name: validation.MaxLength, Rule: 64, Chain: nil},
   153  				{Target: "personGroupID", Name: validation.Pattern, Rule: `^[a-z0-9-_]+$`, Chain: nil}}}}); err != nil {
   154  		return result, validation.NewError("face.PersonGroupClient", "Delete", err.Error())
   155  	}
   156  
   157  	req, err := client.DeletePreparer(ctx, personGroupID)
   158  	if err != nil {
   159  		err = autorest.NewErrorWithError(err, "face.PersonGroupClient", "Delete", nil, "Failure preparing request")
   160  		return
   161  	}
   162  
   163  	resp, err := client.DeleteSender(req)
   164  	if err != nil {
   165  		result.Response = resp
   166  		err = autorest.NewErrorWithError(err, "face.PersonGroupClient", "Delete", resp, "Failure sending request")
   167  		return
   168  	}
   169  
   170  	result, err = client.DeleteResponder(resp)
   171  	if err != nil {
   172  		err = autorest.NewErrorWithError(err, "face.PersonGroupClient", "Delete", resp, "Failure responding to request")
   173  		return
   174  	}
   175  
   176  	return
   177  }
   178  
   179  // DeletePreparer prepares the Delete request.
   180  func (client PersonGroupClient) DeletePreparer(ctx context.Context, personGroupID string) (*http.Request, error) {
   181  	urlParameters := map[string]interface{}{
   182  		"Endpoint": client.Endpoint,
   183  	}
   184  
   185  	pathParameters := map[string]interface{}{
   186  		"personGroupId": autorest.Encode("path", personGroupID),
   187  	}
   188  
   189  	preparer := autorest.CreatePreparer(
   190  		autorest.AsDelete(),
   191  		autorest.WithCustomBaseURL("{Endpoint}/face/v1.0", urlParameters),
   192  		autorest.WithPathParameters("/persongroups/{personGroupId}", pathParameters))
   193  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   194  }
   195  
   196  // DeleteSender sends the Delete request. The method will close the
   197  // http.Response Body if it receives an error.
   198  func (client PersonGroupClient) DeleteSender(req *http.Request) (*http.Response, error) {
   199  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   200  }
   201  
   202  // DeleteResponder handles the response to the Delete request. The method always
   203  // closes the http.Response Body.
   204  func (client PersonGroupClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   205  	err = autorest.Respond(
   206  		resp,
   207  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   208  		autorest.ByClosing())
   209  	result.Response = resp
   210  	return
   211  }
   212  
   213  // Get retrieve person group name, userData and recognitionModel. To get person information under this personGroup, use
   214  // [PersonGroup Person - List](https://docs.microsoft.com/rest/api/cognitiveservices/face/persongroupperson/list).
   215  // Parameters:
   216  // personGroupID - id referencing a particular person group.
   217  // returnRecognitionModel - a value indicating whether the operation should return 'recognitionModel' in
   218  // response.
   219  func (client PersonGroupClient) Get(ctx context.Context, personGroupID string, returnRecognitionModel *bool) (result PersonGroup, err error) {
   220  	if tracing.IsEnabled() {
   221  		ctx = tracing.StartSpan(ctx, fqdn+"/PersonGroupClient.Get")
   222  		defer func() {
   223  			sc := -1
   224  			if result.Response.Response != nil {
   225  				sc = result.Response.Response.StatusCode
   226  			}
   227  			tracing.EndSpan(ctx, sc, err)
   228  		}()
   229  	}
   230  	if err := validation.Validate([]validation.Validation{
   231  		{TargetValue: personGroupID,
   232  			Constraints: []validation.Constraint{{Target: "personGroupID", Name: validation.MaxLength, Rule: 64, Chain: nil},
   233  				{Target: "personGroupID", Name: validation.Pattern, Rule: `^[a-z0-9-_]+$`, Chain: nil}}}}); err != nil {
   234  		return result, validation.NewError("face.PersonGroupClient", "Get", err.Error())
   235  	}
   236  
   237  	req, err := client.GetPreparer(ctx, personGroupID, returnRecognitionModel)
   238  	if err != nil {
   239  		err = autorest.NewErrorWithError(err, "face.PersonGroupClient", "Get", nil, "Failure preparing request")
   240  		return
   241  	}
   242  
   243  	resp, err := client.GetSender(req)
   244  	if err != nil {
   245  		result.Response = autorest.Response{Response: resp}
   246  		err = autorest.NewErrorWithError(err, "face.PersonGroupClient", "Get", resp, "Failure sending request")
   247  		return
   248  	}
   249  
   250  	result, err = client.GetResponder(resp)
   251  	if err != nil {
   252  		err = autorest.NewErrorWithError(err, "face.PersonGroupClient", "Get", resp, "Failure responding to request")
   253  		return
   254  	}
   255  
   256  	return
   257  }
   258  
   259  // GetPreparer prepares the Get request.
   260  func (client PersonGroupClient) GetPreparer(ctx context.Context, personGroupID string, returnRecognitionModel *bool) (*http.Request, error) {
   261  	urlParameters := map[string]interface{}{
   262  		"Endpoint": client.Endpoint,
   263  	}
   264  
   265  	pathParameters := map[string]interface{}{
   266  		"personGroupId": autorest.Encode("path", personGroupID),
   267  	}
   268  
   269  	queryParameters := map[string]interface{}{}
   270  	if returnRecognitionModel != nil {
   271  		queryParameters["returnRecognitionModel"] = autorest.Encode("query", *returnRecognitionModel)
   272  	} else {
   273  		queryParameters["returnRecognitionModel"] = autorest.Encode("query", false)
   274  	}
   275  
   276  	preparer := autorest.CreatePreparer(
   277  		autorest.AsGet(),
   278  		autorest.WithCustomBaseURL("{Endpoint}/face/v1.0", urlParameters),
   279  		autorest.WithPathParameters("/persongroups/{personGroupId}", pathParameters),
   280  		autorest.WithQueryParameters(queryParameters))
   281  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   282  }
   283  
   284  // GetSender sends the Get request. The method will close the
   285  // http.Response Body if it receives an error.
   286  func (client PersonGroupClient) GetSender(req *http.Request) (*http.Response, error) {
   287  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   288  }
   289  
   290  // GetResponder handles the response to the Get request. The method always
   291  // closes the http.Response Body.
   292  func (client PersonGroupClient) GetResponder(resp *http.Response) (result PersonGroup, err error) {
   293  	err = autorest.Respond(
   294  		resp,
   295  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   296  		autorest.ByUnmarshallingJSON(&result),
   297  		autorest.ByClosing())
   298  	result.Response = autorest.Response{Response: resp}
   299  	return
   300  }
   301  
   302  // GetTrainingStatus retrieve the training status of a person group (completed or ongoing).
   303  // Parameters:
   304  // personGroupID - id referencing a particular person group.
   305  func (client PersonGroupClient) GetTrainingStatus(ctx context.Context, personGroupID string) (result TrainingStatus, err error) {
   306  	if tracing.IsEnabled() {
   307  		ctx = tracing.StartSpan(ctx, fqdn+"/PersonGroupClient.GetTrainingStatus")
   308  		defer func() {
   309  			sc := -1
   310  			if result.Response.Response != nil {
   311  				sc = result.Response.Response.StatusCode
   312  			}
   313  			tracing.EndSpan(ctx, sc, err)
   314  		}()
   315  	}
   316  	if err := validation.Validate([]validation.Validation{
   317  		{TargetValue: personGroupID,
   318  			Constraints: []validation.Constraint{{Target: "personGroupID", Name: validation.MaxLength, Rule: 64, Chain: nil},
   319  				{Target: "personGroupID", Name: validation.Pattern, Rule: `^[a-z0-9-_]+$`, Chain: nil}}}}); err != nil {
   320  		return result, validation.NewError("face.PersonGroupClient", "GetTrainingStatus", err.Error())
   321  	}
   322  
   323  	req, err := client.GetTrainingStatusPreparer(ctx, personGroupID)
   324  	if err != nil {
   325  		err = autorest.NewErrorWithError(err, "face.PersonGroupClient", "GetTrainingStatus", nil, "Failure preparing request")
   326  		return
   327  	}
   328  
   329  	resp, err := client.GetTrainingStatusSender(req)
   330  	if err != nil {
   331  		result.Response = autorest.Response{Response: resp}
   332  		err = autorest.NewErrorWithError(err, "face.PersonGroupClient", "GetTrainingStatus", resp, "Failure sending request")
   333  		return
   334  	}
   335  
   336  	result, err = client.GetTrainingStatusResponder(resp)
   337  	if err != nil {
   338  		err = autorest.NewErrorWithError(err, "face.PersonGroupClient", "GetTrainingStatus", resp, "Failure responding to request")
   339  		return
   340  	}
   341  
   342  	return
   343  }
   344  
   345  // GetTrainingStatusPreparer prepares the GetTrainingStatus request.
   346  func (client PersonGroupClient) GetTrainingStatusPreparer(ctx context.Context, personGroupID string) (*http.Request, error) {
   347  	urlParameters := map[string]interface{}{
   348  		"Endpoint": client.Endpoint,
   349  	}
   350  
   351  	pathParameters := map[string]interface{}{
   352  		"personGroupId": autorest.Encode("path", personGroupID),
   353  	}
   354  
   355  	preparer := autorest.CreatePreparer(
   356  		autorest.AsGet(),
   357  		autorest.WithCustomBaseURL("{Endpoint}/face/v1.0", urlParameters),
   358  		autorest.WithPathParameters("/persongroups/{personGroupId}/training", pathParameters))
   359  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   360  }
   361  
   362  // GetTrainingStatusSender sends the GetTrainingStatus request. The method will close the
   363  // http.Response Body if it receives an error.
   364  func (client PersonGroupClient) GetTrainingStatusSender(req *http.Request) (*http.Response, error) {
   365  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   366  }
   367  
   368  // GetTrainingStatusResponder handles the response to the GetTrainingStatus request. The method always
   369  // closes the http.Response Body.
   370  func (client PersonGroupClient) GetTrainingStatusResponder(resp *http.Response) (result TrainingStatus, err error) {
   371  	err = autorest.Respond(
   372  		resp,
   373  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   374  		autorest.ByUnmarshallingJSON(&result),
   375  		autorest.ByClosing())
   376  	result.Response = autorest.Response{Response: resp}
   377  	return
   378  }
   379  
   380  // List list person groups’ personGroupId, name, userData and recognitionModel.<br />
   381  // * Person groups are stored in alphabetical order of personGroupId.
   382  // * "start" parameter (string, optional) is a user-provided personGroupId value that returned entries have larger ids
   383  // by string comparison. "start" set to empty to indicate return from the first item.
   384  // * "top" parameter (int, optional) specifies the number of entries to return. A maximal of 1000 entries can be
   385  // returned in one call. To fetch more, you can specify "start" with the last returned entry’s Id of the current call.
   386  // <br />
   387  // For example, total 5 person groups: "group1", ..., "group5".
   388  // <br /> "start=&top=" will return all 5 groups.
   389  // <br /> "start=&top=2" will return "group1", "group2".
   390  // <br /> "start=group2&top=3" will return "group3", "group4", "group5".
   391  // Parameters:
   392  // start - list person groups from the least personGroupId greater than the "start".
   393  // top - the number of person groups to list.
   394  // returnRecognitionModel - a value indicating whether the operation should return 'recognitionModel' in
   395  // response.
   396  func (client PersonGroupClient) List(ctx context.Context, start string, top *int32, returnRecognitionModel *bool) (result ListPersonGroup, err error) {
   397  	if tracing.IsEnabled() {
   398  		ctx = tracing.StartSpan(ctx, fqdn+"/PersonGroupClient.List")
   399  		defer func() {
   400  			sc := -1
   401  			if result.Response.Response != nil {
   402  				sc = result.Response.Response.StatusCode
   403  			}
   404  			tracing.EndSpan(ctx, sc, err)
   405  		}()
   406  	}
   407  	if err := validation.Validate([]validation.Validation{
   408  		{TargetValue: start,
   409  			Constraints: []validation.Constraint{{Target: "start", Name: validation.Empty, Rule: false,
   410  				Chain: []validation.Constraint{{Target: "start", Name: validation.MaxLength, Rule: 64, Chain: nil}}}}},
   411  		{TargetValue: top,
   412  			Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false,
   413  				Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMaximum, Rule: int64(1000), Chain: nil},
   414  					{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil},
   415  				}}}}}); err != nil {
   416  		return result, validation.NewError("face.PersonGroupClient", "List", err.Error())
   417  	}
   418  
   419  	req, err := client.ListPreparer(ctx, start, top, returnRecognitionModel)
   420  	if err != nil {
   421  		err = autorest.NewErrorWithError(err, "face.PersonGroupClient", "List", nil, "Failure preparing request")
   422  		return
   423  	}
   424  
   425  	resp, err := client.ListSender(req)
   426  	if err != nil {
   427  		result.Response = autorest.Response{Response: resp}
   428  		err = autorest.NewErrorWithError(err, "face.PersonGroupClient", "List", resp, "Failure sending request")
   429  		return
   430  	}
   431  
   432  	result, err = client.ListResponder(resp)
   433  	if err != nil {
   434  		err = autorest.NewErrorWithError(err, "face.PersonGroupClient", "List", resp, "Failure responding to request")
   435  		return
   436  	}
   437  
   438  	return
   439  }
   440  
   441  // ListPreparer prepares the List request.
   442  func (client PersonGroupClient) ListPreparer(ctx context.Context, start string, top *int32, returnRecognitionModel *bool) (*http.Request, error) {
   443  	urlParameters := map[string]interface{}{
   444  		"Endpoint": client.Endpoint,
   445  	}
   446  
   447  	queryParameters := map[string]interface{}{}
   448  	if len(start) > 0 {
   449  		queryParameters["start"] = autorest.Encode("query", start)
   450  	}
   451  	if top != nil {
   452  		queryParameters["top"] = autorest.Encode("query", *top)
   453  	} else {
   454  		queryParameters["top"] = autorest.Encode("query", 1000)
   455  	}
   456  	if returnRecognitionModel != nil {
   457  		queryParameters["returnRecognitionModel"] = autorest.Encode("query", *returnRecognitionModel)
   458  	} else {
   459  		queryParameters["returnRecognitionModel"] = autorest.Encode("query", false)
   460  	}
   461  
   462  	preparer := autorest.CreatePreparer(
   463  		autorest.AsGet(),
   464  		autorest.WithCustomBaseURL("{Endpoint}/face/v1.0", urlParameters),
   465  		autorest.WithPath("/persongroups"),
   466  		autorest.WithQueryParameters(queryParameters))
   467  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   468  }
   469  
   470  // ListSender sends the List request. The method will close the
   471  // http.Response Body if it receives an error.
   472  func (client PersonGroupClient) ListSender(req *http.Request) (*http.Response, error) {
   473  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   474  }
   475  
   476  // ListResponder handles the response to the List request. The method always
   477  // closes the http.Response Body.
   478  func (client PersonGroupClient) ListResponder(resp *http.Response) (result ListPersonGroup, err error) {
   479  	err = autorest.Respond(
   480  		resp,
   481  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   482  		autorest.ByUnmarshallingJSON(&result.Value),
   483  		autorest.ByClosing())
   484  	result.Response = autorest.Response{Response: resp}
   485  	return
   486  }
   487  
   488  // Train queue a person group training task, the training task may not be started immediately.
   489  // Parameters:
   490  // personGroupID - id referencing a particular person group.
   491  func (client PersonGroupClient) Train(ctx context.Context, personGroupID string) (result autorest.Response, err error) {
   492  	if tracing.IsEnabled() {
   493  		ctx = tracing.StartSpan(ctx, fqdn+"/PersonGroupClient.Train")
   494  		defer func() {
   495  			sc := -1
   496  			if result.Response != nil {
   497  				sc = result.Response.StatusCode
   498  			}
   499  			tracing.EndSpan(ctx, sc, err)
   500  		}()
   501  	}
   502  	if err := validation.Validate([]validation.Validation{
   503  		{TargetValue: personGroupID,
   504  			Constraints: []validation.Constraint{{Target: "personGroupID", Name: validation.MaxLength, Rule: 64, Chain: nil},
   505  				{Target: "personGroupID", Name: validation.Pattern, Rule: `^[a-z0-9-_]+$`, Chain: nil}}}}); err != nil {
   506  		return result, validation.NewError("face.PersonGroupClient", "Train", err.Error())
   507  	}
   508  
   509  	req, err := client.TrainPreparer(ctx, personGroupID)
   510  	if err != nil {
   511  		err = autorest.NewErrorWithError(err, "face.PersonGroupClient", "Train", nil, "Failure preparing request")
   512  		return
   513  	}
   514  
   515  	resp, err := client.TrainSender(req)
   516  	if err != nil {
   517  		result.Response = resp
   518  		err = autorest.NewErrorWithError(err, "face.PersonGroupClient", "Train", resp, "Failure sending request")
   519  		return
   520  	}
   521  
   522  	result, err = client.TrainResponder(resp)
   523  	if err != nil {
   524  		err = autorest.NewErrorWithError(err, "face.PersonGroupClient", "Train", resp, "Failure responding to request")
   525  		return
   526  	}
   527  
   528  	return
   529  }
   530  
   531  // TrainPreparer prepares the Train request.
   532  func (client PersonGroupClient) TrainPreparer(ctx context.Context, personGroupID string) (*http.Request, error) {
   533  	urlParameters := map[string]interface{}{
   534  		"Endpoint": client.Endpoint,
   535  	}
   536  
   537  	pathParameters := map[string]interface{}{
   538  		"personGroupId": autorest.Encode("path", personGroupID),
   539  	}
   540  
   541  	preparer := autorest.CreatePreparer(
   542  		autorest.AsPost(),
   543  		autorest.WithCustomBaseURL("{Endpoint}/face/v1.0", urlParameters),
   544  		autorest.WithPathParameters("/persongroups/{personGroupId}/train", pathParameters))
   545  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   546  }
   547  
   548  // TrainSender sends the Train request. The method will close the
   549  // http.Response Body if it receives an error.
   550  func (client PersonGroupClient) TrainSender(req *http.Request) (*http.Response, error) {
   551  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   552  }
   553  
   554  // TrainResponder handles the response to the Train request. The method always
   555  // closes the http.Response Body.
   556  func (client PersonGroupClient) TrainResponder(resp *http.Response) (result autorest.Response, err error) {
   557  	err = autorest.Respond(
   558  		resp,
   559  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   560  		autorest.ByClosing())
   561  	result.Response = resp
   562  	return
   563  }
   564  
   565  // Update update an existing person group's display name and userData. The properties which does not appear in request
   566  // body will not be updated.
   567  // Parameters:
   568  // personGroupID - id referencing a particular person group.
   569  // body - request body for updating person group.
   570  func (client PersonGroupClient) Update(ctx context.Context, personGroupID string, body NameAndUserDataContract) (result autorest.Response, err error) {
   571  	if tracing.IsEnabled() {
   572  		ctx = tracing.StartSpan(ctx, fqdn+"/PersonGroupClient.Update")
   573  		defer func() {
   574  			sc := -1
   575  			if result.Response != nil {
   576  				sc = result.Response.StatusCode
   577  			}
   578  			tracing.EndSpan(ctx, sc, err)
   579  		}()
   580  	}
   581  	if err := validation.Validate([]validation.Validation{
   582  		{TargetValue: personGroupID,
   583  			Constraints: []validation.Constraint{{Target: "personGroupID", Name: validation.MaxLength, Rule: 64, Chain: nil},
   584  				{Target: "personGroupID", Name: validation.Pattern, Rule: `^[a-z0-9-_]+$`, Chain: nil}}}}); err != nil {
   585  		return result, validation.NewError("face.PersonGroupClient", "Update", err.Error())
   586  	}
   587  
   588  	req, err := client.UpdatePreparer(ctx, personGroupID, body)
   589  	if err != nil {
   590  		err = autorest.NewErrorWithError(err, "face.PersonGroupClient", "Update", nil, "Failure preparing request")
   591  		return
   592  	}
   593  
   594  	resp, err := client.UpdateSender(req)
   595  	if err != nil {
   596  		result.Response = resp
   597  		err = autorest.NewErrorWithError(err, "face.PersonGroupClient", "Update", resp, "Failure sending request")
   598  		return
   599  	}
   600  
   601  	result, err = client.UpdateResponder(resp)
   602  	if err != nil {
   603  		err = autorest.NewErrorWithError(err, "face.PersonGroupClient", "Update", resp, "Failure responding to request")
   604  		return
   605  	}
   606  
   607  	return
   608  }
   609  
   610  // UpdatePreparer prepares the Update request.
   611  func (client PersonGroupClient) UpdatePreparer(ctx context.Context, personGroupID string, body NameAndUserDataContract) (*http.Request, error) {
   612  	urlParameters := map[string]interface{}{
   613  		"Endpoint": client.Endpoint,
   614  	}
   615  
   616  	pathParameters := map[string]interface{}{
   617  		"personGroupId": autorest.Encode("path", personGroupID),
   618  	}
   619  
   620  	preparer := autorest.CreatePreparer(
   621  		autorest.AsContentType("application/json; charset=utf-8"),
   622  		autorest.AsPatch(),
   623  		autorest.WithCustomBaseURL("{Endpoint}/face/v1.0", urlParameters),
   624  		autorest.WithPathParameters("/persongroups/{personGroupId}", pathParameters),
   625  		autorest.WithJSON(body))
   626  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   627  }
   628  
   629  // UpdateSender sends the Update request. The method will close the
   630  // http.Response Body if it receives an error.
   631  func (client PersonGroupClient) UpdateSender(req *http.Request) (*http.Response, error) {
   632  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   633  }
   634  
   635  // UpdateResponder handles the response to the Update request. The method always
   636  // closes the http.Response Body.
   637  func (client PersonGroupClient) UpdateResponder(resp *http.Response) (result autorest.Response, err error) {
   638  	err = autorest.Respond(
   639  		resp,
   640  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   641  		autorest.ByClosing())
   642  	result.Response = resp
   643  	return
   644  }
   645  

View as plain text