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// BgpServiceCommunitiesClient is the network Client
18type BgpServiceCommunitiesClient struct {
19	BaseClient
20}
21
22// NewBgpServiceCommunitiesClient creates an instance of the BgpServiceCommunitiesClient client.
23func NewBgpServiceCommunitiesClient(subscriptionID string) BgpServiceCommunitiesClient {
24	return NewBgpServiceCommunitiesClientWithBaseURI(DefaultBaseURI, subscriptionID)
25}
26
27// NewBgpServiceCommunitiesClientWithBaseURI creates an instance of the BgpServiceCommunitiesClient client using a
28// custom endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds,
29// Azure stack).
30func NewBgpServiceCommunitiesClientWithBaseURI(baseURI string, subscriptionID string) BgpServiceCommunitiesClient {
31	return BgpServiceCommunitiesClient{NewWithBaseURI(baseURI, subscriptionID)}
32}
33
34// List gets all the available bgp service communities.
35func (client BgpServiceCommunitiesClient) List(ctx context.Context) (result BgpServiceCommunityListResultPage, err error) {
36	if tracing.IsEnabled() {
37		ctx = tracing.StartSpan(ctx, fqdn+"/BgpServiceCommunitiesClient.List")
38		defer func() {
39			sc := -1
40			if result.bsclr.Response.Response != nil {
41				sc = result.bsclr.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.BgpServiceCommunitiesClient", "List", nil, "Failure preparing request")
50		return
51	}
52
53	resp, err := client.ListSender(req)
54	if err != nil {
55		result.bsclr.Response = autorest.Response{Response: resp}
56		err = autorest.NewErrorWithError(err, "network.BgpServiceCommunitiesClient", "List", resp, "Failure sending request")
57		return
58	}
59
60	result.bsclr, err = client.ListResponder(resp)
61	if err != nil {
62		err = autorest.NewErrorWithError(err, "network.BgpServiceCommunitiesClient", "List", resp, "Failure responding to request")
63		return
64	}
65	if result.bsclr.hasNextLink() && result.bsclr.IsEmpty() {
66		err = result.NextWithContext(ctx)
67		return
68	}
69
70	return
71}
72
73// ListPreparer prepares the List request.
74func (client BgpServiceCommunitiesClient) ListPreparer(ctx context.Context) (*http.Request, error) {
75	pathParameters := map[string]interface{}{
76		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
77	}
78
79	const APIVersion = "2016-12-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/bgpServiceCommunities", 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 BgpServiceCommunitiesClient) 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 BgpServiceCommunitiesClient) ListResponder(resp *http.Response) (result BgpServiceCommunityListResult, 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 BgpServiceCommunitiesClient) listNextResults(ctx context.Context, lastResults BgpServiceCommunityListResult) (result BgpServiceCommunityListResult, err error) {
112	req, err := lastResults.bgpServiceCommunityListResultPreparer(ctx)
113	if err != nil {
114		return result, autorest.NewErrorWithError(err, "network.BgpServiceCommunitiesClient", "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.BgpServiceCommunitiesClient", "listNextResults", resp, "Failure sending next results request")
123	}
124	result, err = client.ListResponder(resp)
125	if err != nil {
126		err = autorest.NewErrorWithError(err, "network.BgpServiceCommunitiesClient", "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 BgpServiceCommunitiesClient) ListComplete(ctx context.Context) (result BgpServiceCommunityListResultIterator, err error) {
133	if tracing.IsEnabled() {
134		ctx = tracing.StartSpan(ctx, fqdn+"/BgpServiceCommunitiesClient.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