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