...

Source file src/github.com/Azure/azure-sdk-for-go/services/apimanagement/mgmt/2020-12-01/apimanagement/apirevision.go

Documentation: github.com/Azure/azure-sdk-for-go/services/apimanagement/mgmt/2020-12-01/apimanagement

     1  package apimanagement
     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  // APIRevisionClient is the apiManagement Client
    19  type APIRevisionClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewAPIRevisionClient creates an instance of the APIRevisionClient client.
    24  func NewAPIRevisionClient(subscriptionID string) APIRevisionClient {
    25  	return NewAPIRevisionClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewAPIRevisionClientWithBaseURI creates an instance of the APIRevisionClient client using a custom endpoint.  Use
    29  // this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    30  func NewAPIRevisionClientWithBaseURI(baseURI string, subscriptionID string) APIRevisionClient {
    31  	return APIRevisionClient{NewWithBaseURI(baseURI, subscriptionID)}
    32  }
    33  
    34  // ListByService lists all revisions of an API.
    35  // Parameters:
    36  // resourceGroupName - the name of the resource group.
    37  // serviceName - the name of the API Management service.
    38  // apiid - API identifier. Must be unique in the current API Management service instance.
    39  // filter - |     Field     |     Usage     |     Supported operators     |     Supported functions
    40  // |</br>|-------------|-------------|-------------|-------------|</br>| apiRevision | filter | ge, le, eq, ne,
    41  // gt, lt | substringof, contains, startswith, endswith |</br>
    42  // top - number of records to return.
    43  // skip - number of records to skip.
    44  func (client APIRevisionClient) ListByService(ctx context.Context, resourceGroupName string, serviceName string, apiid string, filter string, top *int32, skip *int32) (result APIRevisionCollectionPage, err error) {
    45  	if tracing.IsEnabled() {
    46  		ctx = tracing.StartSpan(ctx, fqdn+"/APIRevisionClient.ListByService")
    47  		defer func() {
    48  			sc := -1
    49  			if result.arc.Response.Response != nil {
    50  				sc = result.arc.Response.Response.StatusCode
    51  			}
    52  			tracing.EndSpan(ctx, sc, err)
    53  		}()
    54  	}
    55  	if err := validation.Validate([]validation.Validation{
    56  		{TargetValue: serviceName,
    57  			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
    58  				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
    59  				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
    60  		{TargetValue: apiid,
    61  			Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 80, Chain: nil},
    62  				{Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil}}},
    63  		{TargetValue: top,
    64  			Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false,
    65  				Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil}}}}},
    66  		{TargetValue: skip,
    67  			Constraints: []validation.Constraint{{Target: "skip", Name: validation.Null, Rule: false,
    68  				Chain: []validation.Constraint{{Target: "skip", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil {
    69  		return result, validation.NewError("apimanagement.APIRevisionClient", "ListByService", err.Error())
    70  	}
    71  
    72  	result.fn = client.listByServiceNextResults
    73  	req, err := client.ListByServicePreparer(ctx, resourceGroupName, serviceName, apiid, filter, top, skip)
    74  	if err != nil {
    75  		err = autorest.NewErrorWithError(err, "apimanagement.APIRevisionClient", "ListByService", nil, "Failure preparing request")
    76  		return
    77  	}
    78  
    79  	resp, err := client.ListByServiceSender(req)
    80  	if err != nil {
    81  		result.arc.Response = autorest.Response{Response: resp}
    82  		err = autorest.NewErrorWithError(err, "apimanagement.APIRevisionClient", "ListByService", resp, "Failure sending request")
    83  		return
    84  	}
    85  
    86  	result.arc, err = client.ListByServiceResponder(resp)
    87  	if err != nil {
    88  		err = autorest.NewErrorWithError(err, "apimanagement.APIRevisionClient", "ListByService", resp, "Failure responding to request")
    89  		return
    90  	}
    91  	if result.arc.hasNextLink() && result.arc.IsEmpty() {
    92  		err = result.NextWithContext(ctx)
    93  		return
    94  	}
    95  
    96  	return
    97  }
    98  
    99  // ListByServicePreparer prepares the ListByService request.
   100  func (client APIRevisionClient) ListByServicePreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, filter string, top *int32, skip *int32) (*http.Request, error) {
   101  	pathParameters := map[string]interface{}{
   102  		"apiId":             autorest.Encode("path", apiid),
   103  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   104  		"serviceName":       autorest.Encode("path", serviceName),
   105  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   106  	}
   107  
   108  	const APIVersion = "2020-12-01"
   109  	queryParameters := map[string]interface{}{
   110  		"api-version": APIVersion,
   111  	}
   112  	if len(filter) > 0 {
   113  		queryParameters["$filter"] = autorest.Encode("query", filter)
   114  	}
   115  	if top != nil {
   116  		queryParameters["$top"] = autorest.Encode("query", *top)
   117  	}
   118  	if skip != nil {
   119  		queryParameters["$skip"] = autorest.Encode("query", *skip)
   120  	}
   121  
   122  	preparer := autorest.CreatePreparer(
   123  		autorest.AsGet(),
   124  		autorest.WithBaseURL(client.BaseURI),
   125  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/revisions", pathParameters),
   126  		autorest.WithQueryParameters(queryParameters))
   127  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   128  }
   129  
   130  // ListByServiceSender sends the ListByService request. The method will close the
   131  // http.Response Body if it receives an error.
   132  func (client APIRevisionClient) ListByServiceSender(req *http.Request) (*http.Response, error) {
   133  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   134  }
   135  
   136  // ListByServiceResponder handles the response to the ListByService request. The method always
   137  // closes the http.Response Body.
   138  func (client APIRevisionClient) ListByServiceResponder(resp *http.Response) (result APIRevisionCollection, err error) {
   139  	err = autorest.Respond(
   140  		resp,
   141  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   142  		autorest.ByUnmarshallingJSON(&result),
   143  		autorest.ByClosing())
   144  	result.Response = autorest.Response{Response: resp}
   145  	return
   146  }
   147  
   148  // listByServiceNextResults retrieves the next set of results, if any.
   149  func (client APIRevisionClient) listByServiceNextResults(ctx context.Context, lastResults APIRevisionCollection) (result APIRevisionCollection, err error) {
   150  	req, err := lastResults.aPIRevisionCollectionPreparer(ctx)
   151  	if err != nil {
   152  		return result, autorest.NewErrorWithError(err, "apimanagement.APIRevisionClient", "listByServiceNextResults", nil, "Failure preparing next results request")
   153  	}
   154  	if req == nil {
   155  		return
   156  	}
   157  	resp, err := client.ListByServiceSender(req)
   158  	if err != nil {
   159  		result.Response = autorest.Response{Response: resp}
   160  		return result, autorest.NewErrorWithError(err, "apimanagement.APIRevisionClient", "listByServiceNextResults", resp, "Failure sending next results request")
   161  	}
   162  	result, err = client.ListByServiceResponder(resp)
   163  	if err != nil {
   164  		err = autorest.NewErrorWithError(err, "apimanagement.APIRevisionClient", "listByServiceNextResults", resp, "Failure responding to next results request")
   165  	}
   166  	return
   167  }
   168  
   169  // ListByServiceComplete enumerates all values, automatically crossing page boundaries as required.
   170  func (client APIRevisionClient) ListByServiceComplete(ctx context.Context, resourceGroupName string, serviceName string, apiid string, filter string, top *int32, skip *int32) (result APIRevisionCollectionIterator, err error) {
   171  	if tracing.IsEnabled() {
   172  		ctx = tracing.StartSpan(ctx, fqdn+"/APIRevisionClient.ListByService")
   173  		defer func() {
   174  			sc := -1
   175  			if result.Response().Response.Response != nil {
   176  				sc = result.page.Response().Response.Response.StatusCode
   177  			}
   178  			tracing.EndSpan(ctx, sc, err)
   179  		}()
   180  	}
   181  	result.page, err = client.ListByService(ctx, resourceGroupName, serviceName, apiid, filter, top, skip)
   182  	return
   183  }
   184  

View as plain text