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