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