1package peering 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/tracing" 25 "net/http" 26) 27 28// ServiceLocationsClient is the peering Client 29type ServiceLocationsClient struct { 30 BaseClient 31} 32 33// NewServiceLocationsClient creates an instance of the ServiceLocationsClient client. 34func NewServiceLocationsClient(subscriptionID string) ServiceLocationsClient { 35 return NewServiceLocationsClientWithBaseURI(DefaultBaseURI, subscriptionID) 36} 37 38// NewServiceLocationsClientWithBaseURI creates an instance of the ServiceLocationsClient client. 39func NewServiceLocationsClientWithBaseURI(baseURI string, subscriptionID string) ServiceLocationsClient { 40 return ServiceLocationsClient{NewWithBaseURI(baseURI, subscriptionID)} 41} 42 43// List lists all of the available peering service locations for the specified kind of peering. 44func (client ServiceLocationsClient) List(ctx context.Context) (result ServiceLocationListResultPage, err error) { 45 if tracing.IsEnabled() { 46 ctx = tracing.StartSpan(ctx, fqdn+"/ServiceLocationsClient.List") 47 defer func() { 48 sc := -1 49 if result.sllr.Response.Response != nil { 50 sc = result.sllr.Response.Response.StatusCode 51 } 52 tracing.EndSpan(ctx, sc, err) 53 }() 54 } 55 result.fn = client.listNextResults 56 req, err := client.ListPreparer(ctx) 57 if err != nil { 58 err = autorest.NewErrorWithError(err, "peering.ServiceLocationsClient", "List", nil, "Failure preparing request") 59 return 60 } 61 62 resp, err := client.ListSender(req) 63 if err != nil { 64 result.sllr.Response = autorest.Response{Response: resp} 65 err = autorest.NewErrorWithError(err, "peering.ServiceLocationsClient", "List", resp, "Failure sending request") 66 return 67 } 68 69 result.sllr, err = client.ListResponder(resp) 70 if err != nil { 71 err = autorest.NewErrorWithError(err, "peering.ServiceLocationsClient", "List", resp, "Failure responding to request") 72 } 73 74 return 75} 76 77// ListPreparer prepares the List request. 78func (client ServiceLocationsClient) ListPreparer(ctx context.Context) (*http.Request, error) { 79 pathParameters := map[string]interface{}{ 80 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 81 } 82 83 const APIVersion = "2019-09-01-preview" 84 queryParameters := map[string]interface{}{ 85 "api-version": APIVersion, 86 } 87 88 preparer := autorest.CreatePreparer( 89 autorest.AsGet(), 90 autorest.WithBaseURL(client.BaseURI), 91 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Peering/peeringServiceLocations", pathParameters), 92 autorest.WithQueryParameters(queryParameters)) 93 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 94} 95 96// ListSender sends the List request. The method will close the 97// http.Response Body if it receives an error. 98func (client ServiceLocationsClient) ListSender(req *http.Request) (*http.Response, error) { 99 sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client)) 100 return autorest.SendWithSender(client, req, sd...) 101} 102 103// ListResponder handles the response to the List request. The method always 104// closes the http.Response Body. 105func (client ServiceLocationsClient) ListResponder(resp *http.Response) (result ServiceLocationListResult, err error) { 106 err = autorest.Respond( 107 resp, 108 client.ByInspecting(), 109 azure.WithErrorUnlessStatusCode(http.StatusOK), 110 autorest.ByUnmarshallingJSON(&result), 111 autorest.ByClosing()) 112 result.Response = autorest.Response{Response: resp} 113 return 114} 115 116// listNextResults retrieves the next set of results, if any. 117func (client ServiceLocationsClient) listNextResults(ctx context.Context, lastResults ServiceLocationListResult) (result ServiceLocationListResult, err error) { 118 req, err := lastResults.serviceLocationListResultPreparer(ctx) 119 if err != nil { 120 return result, autorest.NewErrorWithError(err, "peering.ServiceLocationsClient", "listNextResults", nil, "Failure preparing next results request") 121 } 122 if req == nil { 123 return 124 } 125 resp, err := client.ListSender(req) 126 if err != nil { 127 result.Response = autorest.Response{Response: resp} 128 return result, autorest.NewErrorWithError(err, "peering.ServiceLocationsClient", "listNextResults", resp, "Failure sending next results request") 129 } 130 result, err = client.ListResponder(resp) 131 if err != nil { 132 err = autorest.NewErrorWithError(err, "peering.ServiceLocationsClient", "listNextResults", resp, "Failure responding to next results request") 133 } 134 return 135} 136 137// ListComplete enumerates all values, automatically crossing page boundaries as required. 138func (client ServiceLocationsClient) ListComplete(ctx context.Context) (result ServiceLocationListResultIterator, err error) { 139 if tracing.IsEnabled() { 140 ctx = tracing.StartSpan(ctx, fqdn+"/ServiceLocationsClient.List") 141 defer func() { 142 sc := -1 143 if result.Response().Response.Response != nil { 144 sc = result.page.Response().Response.Response.StatusCode 145 } 146 tracing.EndSpan(ctx, sc, err) 147 }() 148 } 149 result.page, err = client.List(ctx) 150 return 151} 152