1package apimanagement 2 3// Copyright (c) Microsoft and contributors. All rights reserved. 4// 5// Licensed under the Apache License, Version 2.0 (the "License"); 6// you may not use this file except in compliance with the License. 7// You may obtain a copy of the License at 8// http://www.apache.org/licenses/LICENSE-2.0 9// 10// Unless required by applicable law or agreed to in writing, software 11// distributed under the License is distributed on an "AS IS" BASIS, 12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13// 14// See the License for the specific language governing permissions and 15// limitations under the License. 16// 17// Code generated by Microsoft (R) AutoRest Code Generator. 18// Changes may cause incorrect behavior and will be lost if the code is regenerated. 19 20import ( 21 "context" 22 "github.com/Azure/go-autorest/autorest" 23 "github.com/Azure/go-autorest/autorest/azure" 24 "github.com/Azure/go-autorest/autorest/validation" 25 "net/http" 26) 27 28// APIRevisionsClient is the apiManagement Client 29type APIRevisionsClient struct { 30 BaseClient 31} 32 33// NewAPIRevisionsClient creates an instance of the APIRevisionsClient client. 34func NewAPIRevisionsClient(subscriptionID string) APIRevisionsClient { 35 return NewAPIRevisionsClientWithBaseURI(DefaultBaseURI, subscriptionID) 36} 37 38// NewAPIRevisionsClientWithBaseURI creates an instance of the APIRevisionsClient client. 39func NewAPIRevisionsClientWithBaseURI(baseURI string, subscriptionID string) APIRevisionsClient { 40 return APIRevisionsClient{NewWithBaseURI(baseURI, subscriptionID)} 41} 42 43// List lists all revisions of an API. 44// Parameters: 45// resourceGroupName - the name of the resource group. 46// serviceName - the name of the API Management service. 47// apiid - API identifier. Must be unique in the current API Management service instance. 48// filter - | Field | Supported operators | Supported functions | 49// |-------------|------------------------|-----------------------------------| 50// 51// |apiRevision | ge, le, eq, ne, gt, lt | substringof, contains, startswith, endswith| 52// top - number of records to return. 53// skip - number of records to skip. 54func (client APIRevisionsClient) List(ctx context.Context, resourceGroupName string, serviceName string, apiid string, filter string, top *int32, skip *int32) (result APIRevisionCollectionPage, err error) { 55 if err := validation.Validate([]validation.Validation{ 56 {TargetValue: top, 57 Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, 58 Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: 1, Chain: nil}}}}}, 59 {TargetValue: skip, 60 Constraints: []validation.Constraint{{Target: "skip", Name: validation.Null, Rule: false, 61 Chain: []validation.Constraint{{Target: "skip", Name: validation.InclusiveMinimum, Rule: 0, Chain: nil}}}}}, 62 {TargetValue: serviceName, 63 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 64 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 65 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, 66 {TargetValue: apiid, 67 Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 256, Chain: nil}, 68 {Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil}, 69 {Target: "apiid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil { 70 return result, validation.NewError("apimanagement.APIRevisionsClient", "List", err.Error()) 71 } 72 73 result.fn = client.listNextResults 74 req, err := client.ListPreparer(ctx, resourceGroupName, serviceName, apiid, filter, top, skip) 75 if err != nil { 76 err = autorest.NewErrorWithError(err, "apimanagement.APIRevisionsClient", "List", nil, "Failure preparing request") 77 return 78 } 79 80 resp, err := client.ListSender(req) 81 if err != nil { 82 result.arc.Response = autorest.Response{Response: resp} 83 err = autorest.NewErrorWithError(err, "apimanagement.APIRevisionsClient", "List", resp, "Failure sending request") 84 return 85 } 86 87 result.arc, err = client.ListResponder(resp) 88 if err != nil { 89 err = autorest.NewErrorWithError(err, "apimanagement.APIRevisionsClient", "List", resp, "Failure responding to request") 90 } 91 92 return 93} 94 95// ListPreparer prepares the List request. 96func (client APIRevisionsClient) ListPreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, filter string, top *int32, skip *int32) (*http.Request, error) { 97 pathParameters := map[string]interface{}{ 98 "apiId": autorest.Encode("path", apiid), 99 "resourceGroupName": autorest.Encode("path", resourceGroupName), 100 "serviceName": autorest.Encode("path", serviceName), 101 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 102 } 103 104 const APIVersion = "2017-03-01" 105 queryParameters := map[string]interface{}{ 106 "api-version": APIVersion, 107 } 108 if len(filter) > 0 { 109 queryParameters["$filter"] = autorest.Encode("query", filter) 110 } 111 if top != nil { 112 queryParameters["$top"] = autorest.Encode("query", *top) 113 } 114 if skip != nil { 115 queryParameters["$skip"] = autorest.Encode("query", *skip) 116 } 117 118 preparer := autorest.CreatePreparer( 119 autorest.AsGet(), 120 autorest.WithBaseURL(client.BaseURI), 121 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/revisions", pathParameters), 122 autorest.WithQueryParameters(queryParameters)) 123 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 124} 125 126// ListSender sends the List request. The method will close the 127// http.Response Body if it receives an error. 128func (client APIRevisionsClient) ListSender(req *http.Request) (*http.Response, error) { 129 return autorest.SendWithSender(client, req, 130 azure.DoRetryWithRegistration(client.Client)) 131} 132 133// ListResponder handles the response to the List request. The method always 134// closes the http.Response Body. 135func (client APIRevisionsClient) ListResponder(resp *http.Response) (result APIRevisionCollection, err error) { 136 err = autorest.Respond( 137 resp, 138 client.ByInspecting(), 139 azure.WithErrorUnlessStatusCode(http.StatusOK), 140 autorest.ByUnmarshallingJSON(&result), 141 autorest.ByClosing()) 142 result.Response = autorest.Response{Response: resp} 143 return 144} 145 146// listNextResults retrieves the next set of results, if any. 147func (client APIRevisionsClient) listNextResults(lastResults APIRevisionCollection) (result APIRevisionCollection, err error) { 148 req, err := lastResults.aPIRevisionCollectionPreparer() 149 if err != nil { 150 return result, autorest.NewErrorWithError(err, "apimanagement.APIRevisionsClient", "listNextResults", nil, "Failure preparing next results request") 151 } 152 if req == nil { 153 return 154 } 155 resp, err := client.ListSender(req) 156 if err != nil { 157 result.Response = autorest.Response{Response: resp} 158 return result, autorest.NewErrorWithError(err, "apimanagement.APIRevisionsClient", "listNextResults", resp, "Failure sending next results request") 159 } 160 result, err = client.ListResponder(resp) 161 if err != nil { 162 err = autorest.NewErrorWithError(err, "apimanagement.APIRevisionsClient", "listNextResults", resp, "Failure responding to next results request") 163 } 164 return 165} 166 167// ListComplete enumerates all values, automatically crossing page boundaries as required. 168func (client APIRevisionsClient) ListComplete(ctx context.Context, resourceGroupName string, serviceName string, apiid string, filter string, top *int32, skip *int32) (result APIRevisionCollectionIterator, err error) { 169 result.page, err = client.List(ctx, resourceGroupName, serviceName, apiid, filter, top, skip) 170 return 171} 172