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