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// ExpressRouteServiceProvidersClient is the network Client 29type ExpressRouteServiceProvidersClient struct { 30 BaseClient 31} 32 33// NewExpressRouteServiceProvidersClient creates an instance of the ExpressRouteServiceProvidersClient client. 34func NewExpressRouteServiceProvidersClient(subscriptionID string) ExpressRouteServiceProvidersClient { 35 return NewExpressRouteServiceProvidersClientWithBaseURI(DefaultBaseURI, subscriptionID) 36} 37 38// NewExpressRouteServiceProvidersClientWithBaseURI creates an instance of the ExpressRouteServiceProvidersClient 39// client using a custom endpoint. Use this when interacting with an Azure cloud that uses a non-standard base URI 40// (sovereign clouds, Azure stack). 41func NewExpressRouteServiceProvidersClientWithBaseURI(baseURI string, subscriptionID string) ExpressRouteServiceProvidersClient { 42 return ExpressRouteServiceProvidersClient{NewWithBaseURI(baseURI, subscriptionID)} 43} 44 45// List gets all the available express route service providers. 46func (client ExpressRouteServiceProvidersClient) List(ctx context.Context) (result ExpressRouteServiceProviderListResultPage, err error) { 47 if tracing.IsEnabled() { 48 ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteServiceProvidersClient.List") 49 defer func() { 50 sc := -1 51 if result.ersplr.Response.Response != nil { 52 sc = result.ersplr.Response.Response.StatusCode 53 } 54 tracing.EndSpan(ctx, sc, err) 55 }() 56 } 57 result.fn = client.listNextResults 58 req, err := client.ListPreparer(ctx) 59 if err != nil { 60 err = autorest.NewErrorWithError(err, "network.ExpressRouteServiceProvidersClient", "List", nil, "Failure preparing request") 61 return 62 } 63 64 resp, err := client.ListSender(req) 65 if err != nil { 66 result.ersplr.Response = autorest.Response{Response: resp} 67 err = autorest.NewErrorWithError(err, "network.ExpressRouteServiceProvidersClient", "List", resp, "Failure sending request") 68 return 69 } 70 71 result.ersplr, err = client.ListResponder(resp) 72 if err != nil { 73 err = autorest.NewErrorWithError(err, "network.ExpressRouteServiceProvidersClient", "List", resp, "Failure responding to request") 74 return 75 } 76 if result.ersplr.hasNextLink() && result.ersplr.IsEmpty() { 77 err = result.NextWithContext(ctx) 78 return 79 } 80 81 return 82} 83 84// ListPreparer prepares the List request. 85func (client ExpressRouteServiceProvidersClient) ListPreparer(ctx context.Context) (*http.Request, error) { 86 pathParameters := map[string]interface{}{ 87 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 88 } 89 90 const APIVersion = "2019-07-01" 91 queryParameters := map[string]interface{}{ 92 "api-version": APIVersion, 93 } 94 95 preparer := autorest.CreatePreparer( 96 autorest.AsGet(), 97 autorest.WithBaseURL(client.BaseURI), 98 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Network/expressRouteServiceProviders", pathParameters), 99 autorest.WithQueryParameters(queryParameters)) 100 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 101} 102 103// ListSender sends the List request. The method will close the 104// http.Response Body if it receives an error. 105func (client ExpressRouteServiceProvidersClient) ListSender(req *http.Request) (*http.Response, error) { 106 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 107} 108 109// ListResponder handles the response to the List request. The method always 110// closes the http.Response Body. 111func (client ExpressRouteServiceProvidersClient) ListResponder(resp *http.Response) (result ExpressRouteServiceProviderListResult, err error) { 112 err = autorest.Respond( 113 resp, 114 azure.WithErrorUnlessStatusCode(http.StatusOK), 115 autorest.ByUnmarshallingJSON(&result), 116 autorest.ByClosing()) 117 result.Response = autorest.Response{Response: resp} 118 return 119} 120 121// listNextResults retrieves the next set of results, if any. 122func (client ExpressRouteServiceProvidersClient) listNextResults(ctx context.Context, lastResults ExpressRouteServiceProviderListResult) (result ExpressRouteServiceProviderListResult, err error) { 123 req, err := lastResults.expressRouteServiceProviderListResultPreparer(ctx) 124 if err != nil { 125 return result, autorest.NewErrorWithError(err, "network.ExpressRouteServiceProvidersClient", "listNextResults", nil, "Failure preparing next results request") 126 } 127 if req == nil { 128 return 129 } 130 resp, err := client.ListSender(req) 131 if err != nil { 132 result.Response = autorest.Response{Response: resp} 133 return result, autorest.NewErrorWithError(err, "network.ExpressRouteServiceProvidersClient", "listNextResults", resp, "Failure sending next results request") 134 } 135 result, err = client.ListResponder(resp) 136 if err != nil { 137 err = autorest.NewErrorWithError(err, "network.ExpressRouteServiceProvidersClient", "listNextResults", resp, "Failure responding to next results request") 138 } 139 return 140} 141 142// ListComplete enumerates all values, automatically crossing page boundaries as required. 143func (client ExpressRouteServiceProvidersClient) ListComplete(ctx context.Context) (result ExpressRouteServiceProviderListResultIterator, err error) { 144 if tracing.IsEnabled() { 145 ctx = tracing.StartSpan(ctx, fqdn+"/ExpressRouteServiceProvidersClient.List") 146 defer func() { 147 sc := -1 148 if result.Response().Response.Response != nil { 149 sc = result.page.Response().Response.Response.StatusCode 150 } 151 tracing.EndSpan(ctx, sc, err) 152 }() 153 } 154 result.page, err = client.List(ctx) 155 return 156} 157