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