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