1package network 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// ExpressRoutePortsLocationsClient is the network Client 29type ExpressRoutePortsLocationsClient struct { 30 BaseClient 31} 32 33// NewExpressRoutePortsLocationsClient creates an instance of the ExpressRoutePortsLocationsClient client. 34func NewExpressRoutePortsLocationsClient(subscriptionID string) ExpressRoutePortsLocationsClient { 35 return NewExpressRoutePortsLocationsClientWithBaseURI(DefaultBaseURI, subscriptionID) 36} 37 38// NewExpressRoutePortsLocationsClientWithBaseURI creates an instance of the ExpressRoutePortsLocationsClient client 39// using a custom endpoint. Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign 40// clouds, Azure stack). 41func NewExpressRoutePortsLocationsClientWithBaseURI(baseURI string, subscriptionID string) ExpressRoutePortsLocationsClient { 42 return ExpressRoutePortsLocationsClient{NewWithBaseURI(baseURI, subscriptionID)} 43} 44 45// Get retrieves a single ExpressRoutePort peering location, including the list of available bandwidths available at 46// said peering location. 47// Parameters: 48// locationName - name of the requested ExpressRoutePort peering location. 49func (client ExpressRoutePortsLocationsClient) Get(ctx context.Context, locationName string) (result ExpressRoutePortsLocation, err error) { 50 if tracing.IsEnabled() { 51 ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRoutePortsLocationsClient.Get") 52 defer func() { 53 sc := -1 54 if result.Response.Response != nil { 55 sc = result.Response.Response.StatusCode 56 } 57 tracing.EndSpan(ctx, sc, err) 58 }() 59 } 60 req, err := client.GetPreparer(ctx, locationName) 61 if err != nil { 62 err = autorest.NewErrorWithError(err, "network.ExpressRoutePortsLocationsClient", "Get", nil, "Failure preparing request") 63 return 64 } 65 66 resp, err := client.GetSender(req) 67 if err != nil { 68 result.Response = autorest.Response{Response: resp} 69 err = autorest.NewErrorWithError(err, "network.ExpressRoutePortsLocationsClient", "Get", resp, "Failure sending request") 70 return 71 } 72 73 result, err = client.GetResponder(resp) 74 if err != nil { 75 err = autorest.NewErrorWithError(err, "network.ExpressRoutePortsLocationsClient", "Get", resp, "Failure responding to request") 76 } 77 78 return 79} 80 81// GetPreparer prepares the Get request. 82func (client ExpressRoutePortsLocationsClient) GetPreparer(ctx context.Context, locationName string) (*http.Request, error) { 83 pathParameters := map[string]interface{}{ 84 "locationName": autorest.Encode("path", locationName), 85 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 86 } 87 88 const APIVersion = "2019-11-01" 89 queryParameters := map[string]interface{}{ 90 "api-version": APIVersion, 91 } 92 93 preparer := autorest.CreatePreparer( 94 autorest.AsGet(), 95 autorest.WithBaseURL(client.BaseURI), 96 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Network/ExpressRoutePortsLocations/{locationName}", pathParameters), 97 autorest.WithQueryParameters(queryParameters)) 98 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 99} 100 101// GetSender sends the Get request. The method will close the 102// http.Response Body if it receives an error. 103func (client ExpressRoutePortsLocationsClient) GetSender(req *http.Request) (*http.Response, error) { 104 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 105} 106 107// GetResponder handles the response to the Get request. The method always 108// closes the http.Response Body. 109func (client ExpressRoutePortsLocationsClient) GetResponder(resp *http.Response) (result ExpressRoutePortsLocation, err error) { 110 err = autorest.Respond( 111 resp, 112 client.ByInspecting(), 113 azure.WithErrorUnlessStatusCode(http.StatusOK), 114 autorest.ByUnmarshallingJSON(&result), 115 autorest.ByClosing()) 116 result.Response = autorest.Response{Response: resp} 117 return 118} 119 120// List retrieves all ExpressRoutePort peering locations. Does not return available bandwidths for each location. 121// Available bandwidths can only be obtained when retrieving a specific peering location. 122func (client ExpressRoutePortsLocationsClient) List(ctx context.Context) (result ExpressRoutePortsLocationListResultPage, err error) { 123 if tracing.IsEnabled() { 124 ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRoutePortsLocationsClient.List") 125 defer func() { 126 sc := -1 127 if result.erpllr.Response.Response != nil { 128 sc = result.erpllr.Response.Response.StatusCode 129 } 130 tracing.EndSpan(ctx, sc, err) 131 }() 132 } 133 result.fn = client.listNextResults 134 req, err := client.ListPreparer(ctx) 135 if err != nil { 136 err = autorest.NewErrorWithError(err, "network.ExpressRoutePortsLocationsClient", "List", nil, "Failure preparing request") 137 return 138 } 139 140 resp, err := client.ListSender(req) 141 if err != nil { 142 result.erpllr.Response = autorest.Response{Response: resp} 143 err = autorest.NewErrorWithError(err, "network.ExpressRoutePortsLocationsClient", "List", resp, "Failure sending request") 144 return 145 } 146 147 result.erpllr, err = client.ListResponder(resp) 148 if err != nil { 149 err = autorest.NewErrorWithError(err, "network.ExpressRoutePortsLocationsClient", "List", resp, "Failure responding to request") 150 } 151 152 return 153} 154 155// ListPreparer prepares the List request. 156func (client ExpressRoutePortsLocationsClient) ListPreparer(ctx context.Context) (*http.Request, error) { 157 pathParameters := map[string]interface{}{ 158 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 159 } 160 161 const APIVersion = "2019-11-01" 162 queryParameters := map[string]interface{}{ 163 "api-version": APIVersion, 164 } 165 166 preparer := autorest.CreatePreparer( 167 autorest.AsGet(), 168 autorest.WithBaseURL(client.BaseURI), 169 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Network/ExpressRoutePortsLocations", pathParameters), 170 autorest.WithQueryParameters(queryParameters)) 171 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 172} 173 174// ListSender sends the List request. The method will close the 175// http.Response Body if it receives an error. 176func (client ExpressRoutePortsLocationsClient) ListSender(req *http.Request) (*http.Response, error) { 177 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 178} 179 180// ListResponder handles the response to the List request. The method always 181// closes the http.Response Body. 182func (client ExpressRoutePortsLocationsClient) ListResponder(resp *http.Response) (result ExpressRoutePortsLocationListResult, err error) { 183 err = autorest.Respond( 184 resp, 185 client.ByInspecting(), 186 azure.WithErrorUnlessStatusCode(http.StatusOK), 187 autorest.ByUnmarshallingJSON(&result), 188 autorest.ByClosing()) 189 result.Response = autorest.Response{Response: resp} 190 return 191} 192 193// listNextResults retrieves the next set of results, if any. 194func (client ExpressRoutePortsLocationsClient) listNextResults(ctx context.Context, lastResults ExpressRoutePortsLocationListResult) (result ExpressRoutePortsLocationListResult, err error) { 195 req, err := lastResults.expressRoutePortsLocationListResultPreparer(ctx) 196 if err != nil { 197 return result, autorest.NewErrorWithError(err, "network.ExpressRoutePortsLocationsClient", "listNextResults", nil, "Failure preparing next results request") 198 } 199 if req == nil { 200 return 201 } 202 resp, err := client.ListSender(req) 203 if err != nil { 204 result.Response = autorest.Response{Response: resp} 205 return result, autorest.NewErrorWithError(err, "network.ExpressRoutePortsLocationsClient", "listNextResults", resp, "Failure sending next results request") 206 } 207 result, err = client.ListResponder(resp) 208 if err != nil { 209 err = autorest.NewErrorWithError(err, "network.ExpressRoutePortsLocationsClient", "listNextResults", resp, "Failure responding to next results request") 210 } 211 return 212} 213 214// ListComplete enumerates all values, automatically crossing page boundaries as required. 215func (client ExpressRoutePortsLocationsClient) ListComplete(ctx context.Context) (result ExpressRoutePortsLocationListResultIterator, err error) { 216 if tracing.IsEnabled() { 217 ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRoutePortsLocationsClient.List") 218 defer func() { 219 sc := -1 220 if result.Response().Response.Response != nil { 221 sc = result.page.Response().Response.Response.StatusCode 222 } 223 tracing.EndSpan(ctx, sc, err) 224 }() 225 } 226 result.page, err = client.List(ctx) 227 return 228} 229