1package trafficmanager
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	"net/http"
25)
26
27// EndpointsClient is the client for the Endpoints methods of the Trafficmanager service.
28type EndpointsClient struct {
29	BaseClient
30}
31
32// NewEndpointsClient creates an instance of the EndpointsClient client.
33func NewEndpointsClient(subscriptionID string) EndpointsClient {
34	return NewEndpointsClientWithBaseURI(DefaultBaseURI, subscriptionID)
35}
36
37// NewEndpointsClientWithBaseURI creates an instance of the EndpointsClient client.
38func NewEndpointsClientWithBaseURI(baseURI string, subscriptionID string) EndpointsClient {
39	return EndpointsClient{NewWithBaseURI(baseURI, subscriptionID)}
40}
41
42// CreateOrUpdate create or update a Traffic Manager endpoint.
43// Parameters:
44// resourceGroupName - the name of the resource group containing the Traffic Manager endpoint to be created or
45// updated.
46// profileName - the name of the Traffic Manager profile.
47// endpointType - the type of the Traffic Manager endpoint to be created or updated.
48// endpointName - the name of the Traffic Manager endpoint to be created or updated.
49// parameters - the Traffic Manager endpoint parameters supplied to the CreateOrUpdate operation.
50func (client EndpointsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, profileName string, endpointType string, endpointName string, parameters Endpoint) (result Endpoint, err error) {
51	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, profileName, endpointType, endpointName, parameters)
52	if err != nil {
53		err = autorest.NewErrorWithError(err, "trafficmanager.EndpointsClient", "CreateOrUpdate", nil, "Failure preparing request")
54		return
55	}
56
57	resp, err := client.CreateOrUpdateSender(req)
58	if err != nil {
59		result.Response = autorest.Response{Response: resp}
60		err = autorest.NewErrorWithError(err, "trafficmanager.EndpointsClient", "CreateOrUpdate", resp, "Failure sending request")
61		return
62	}
63
64	result, err = client.CreateOrUpdateResponder(resp)
65	if err != nil {
66		err = autorest.NewErrorWithError(err, "trafficmanager.EndpointsClient", "CreateOrUpdate", resp, "Failure responding to request")
67	}
68
69	return
70}
71
72// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
73func (client EndpointsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, profileName string, endpointType string, endpointName string, parameters Endpoint) (*http.Request, error) {
74	pathParameters := map[string]interface{}{
75		"endpointName":      autorest.Encode("path", endpointName),
76		"endpointType":      autorest.Encode("path", endpointType),
77		"profileName":       autorest.Encode("path", profileName),
78		"resourceGroupName": autorest.Encode("path", resourceGroupName),
79		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
80	}
81
82	const APIVersion = "2017-05-01"
83	queryParameters := map[string]interface{}{
84		"api-version": APIVersion,
85	}
86
87	preparer := autorest.CreatePreparer(
88		autorest.AsContentType("application/json; charset=utf-8"),
89		autorest.AsPut(),
90		autorest.WithBaseURL(client.BaseURI),
91		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/trafficmanagerprofiles/{profileName}/{endpointType}/{endpointName}", pathParameters),
92		autorest.WithJSON(parameters),
93		autorest.WithQueryParameters(queryParameters))
94	return preparer.Prepare((&http.Request{}).WithContext(ctx))
95}
96
97// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
98// http.Response Body if it receives an error.
99func (client EndpointsClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
100	return autorest.SendWithSender(client, req,
101		azure.DoRetryWithRegistration(client.Client))
102}
103
104// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
105// closes the http.Response Body.
106func (client EndpointsClient) CreateOrUpdateResponder(resp *http.Response) (result Endpoint, err error) {
107	err = autorest.Respond(
108		resp,
109		client.ByInspecting(),
110		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
111		autorest.ByUnmarshallingJSON(&result),
112		autorest.ByClosing())
113	result.Response = autorest.Response{Response: resp}
114	return
115}
116
117// Delete deletes a Traffic Manager endpoint.
118// Parameters:
119// resourceGroupName - the name of the resource group containing the Traffic Manager endpoint to be deleted.
120// profileName - the name of the Traffic Manager profile.
121// endpointType - the type of the Traffic Manager endpoint to be deleted.
122// endpointName - the name of the Traffic Manager endpoint to be deleted.
123func (client EndpointsClient) Delete(ctx context.Context, resourceGroupName string, profileName string, endpointType string, endpointName string) (result DeleteOperationResult, err error) {
124	req, err := client.DeletePreparer(ctx, resourceGroupName, profileName, endpointType, endpointName)
125	if err != nil {
126		err = autorest.NewErrorWithError(err, "trafficmanager.EndpointsClient", "Delete", nil, "Failure preparing request")
127		return
128	}
129
130	resp, err := client.DeleteSender(req)
131	if err != nil {
132		result.Response = autorest.Response{Response: resp}
133		err = autorest.NewErrorWithError(err, "trafficmanager.EndpointsClient", "Delete", resp, "Failure sending request")
134		return
135	}
136
137	result, err = client.DeleteResponder(resp)
138	if err != nil {
139		err = autorest.NewErrorWithError(err, "trafficmanager.EndpointsClient", "Delete", resp, "Failure responding to request")
140	}
141
142	return
143}
144
145// DeletePreparer prepares the Delete request.
146func (client EndpointsClient) DeletePreparer(ctx context.Context, resourceGroupName string, profileName string, endpointType string, endpointName string) (*http.Request, error) {
147	pathParameters := map[string]interface{}{
148		"endpointName":      autorest.Encode("path", endpointName),
149		"endpointType":      autorest.Encode("path", endpointType),
150		"profileName":       autorest.Encode("path", profileName),
151		"resourceGroupName": autorest.Encode("path", resourceGroupName),
152		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
153	}
154
155	const APIVersion = "2017-05-01"
156	queryParameters := map[string]interface{}{
157		"api-version": APIVersion,
158	}
159
160	preparer := autorest.CreatePreparer(
161		autorest.AsDelete(),
162		autorest.WithBaseURL(client.BaseURI),
163		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/trafficmanagerprofiles/{profileName}/{endpointType}/{endpointName}", pathParameters),
164		autorest.WithQueryParameters(queryParameters))
165	return preparer.Prepare((&http.Request{}).WithContext(ctx))
166}
167
168// DeleteSender sends the Delete request. The method will close the
169// http.Response Body if it receives an error.
170func (client EndpointsClient) DeleteSender(req *http.Request) (*http.Response, error) {
171	return autorest.SendWithSender(client, req,
172		azure.DoRetryWithRegistration(client.Client))
173}
174
175// DeleteResponder handles the response to the Delete request. The method always
176// closes the http.Response Body.
177func (client EndpointsClient) DeleteResponder(resp *http.Response) (result DeleteOperationResult, err error) {
178	err = autorest.Respond(
179		resp,
180		client.ByInspecting(),
181		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
182		autorest.ByUnmarshallingJSON(&result),
183		autorest.ByClosing())
184	result.Response = autorest.Response{Response: resp}
185	return
186}
187
188// Get gets a Traffic Manager endpoint.
189// Parameters:
190// resourceGroupName - the name of the resource group containing the Traffic Manager endpoint.
191// profileName - the name of the Traffic Manager profile.
192// endpointType - the type of the Traffic Manager endpoint.
193// endpointName - the name of the Traffic Manager endpoint.
194func (client EndpointsClient) Get(ctx context.Context, resourceGroupName string, profileName string, endpointType string, endpointName string) (result Endpoint, err error) {
195	req, err := client.GetPreparer(ctx, resourceGroupName, profileName, endpointType, endpointName)
196	if err != nil {
197		err = autorest.NewErrorWithError(err, "trafficmanager.EndpointsClient", "Get", nil, "Failure preparing request")
198		return
199	}
200
201	resp, err := client.GetSender(req)
202	if err != nil {
203		result.Response = autorest.Response{Response: resp}
204		err = autorest.NewErrorWithError(err, "trafficmanager.EndpointsClient", "Get", resp, "Failure sending request")
205		return
206	}
207
208	result, err = client.GetResponder(resp)
209	if err != nil {
210		err = autorest.NewErrorWithError(err, "trafficmanager.EndpointsClient", "Get", resp, "Failure responding to request")
211	}
212
213	return
214}
215
216// GetPreparer prepares the Get request.
217func (client EndpointsClient) GetPreparer(ctx context.Context, resourceGroupName string, profileName string, endpointType string, endpointName string) (*http.Request, error) {
218	pathParameters := map[string]interface{}{
219		"endpointName":      autorest.Encode("path", endpointName),
220		"endpointType":      autorest.Encode("path", endpointType),
221		"profileName":       autorest.Encode("path", profileName),
222		"resourceGroupName": autorest.Encode("path", resourceGroupName),
223		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
224	}
225
226	const APIVersion = "2017-05-01"
227	queryParameters := map[string]interface{}{
228		"api-version": APIVersion,
229	}
230
231	preparer := autorest.CreatePreparer(
232		autorest.AsGet(),
233		autorest.WithBaseURL(client.BaseURI),
234		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/trafficmanagerprofiles/{profileName}/{endpointType}/{endpointName}", pathParameters),
235		autorest.WithQueryParameters(queryParameters))
236	return preparer.Prepare((&http.Request{}).WithContext(ctx))
237}
238
239// GetSender sends the Get request. The method will close the
240// http.Response Body if it receives an error.
241func (client EndpointsClient) GetSender(req *http.Request) (*http.Response, error) {
242	return autorest.SendWithSender(client, req,
243		azure.DoRetryWithRegistration(client.Client))
244}
245
246// GetResponder handles the response to the Get request. The method always
247// closes the http.Response Body.
248func (client EndpointsClient) GetResponder(resp *http.Response) (result Endpoint, err error) {
249	err = autorest.Respond(
250		resp,
251		client.ByInspecting(),
252		azure.WithErrorUnlessStatusCode(http.StatusOK),
253		autorest.ByUnmarshallingJSON(&result),
254		autorest.ByClosing())
255	result.Response = autorest.Response{Response: resp}
256	return
257}
258
259// Update update a Traffic Manager endpoint.
260// Parameters:
261// resourceGroupName - the name of the resource group containing the Traffic Manager endpoint to be updated.
262// profileName - the name of the Traffic Manager profile.
263// endpointType - the type of the Traffic Manager endpoint to be updated.
264// endpointName - the name of the Traffic Manager endpoint to be updated.
265// parameters - the Traffic Manager endpoint parameters supplied to the Update operation.
266func (client EndpointsClient) Update(ctx context.Context, resourceGroupName string, profileName string, endpointType string, endpointName string, parameters Endpoint) (result Endpoint, err error) {
267	req, err := client.UpdatePreparer(ctx, resourceGroupName, profileName, endpointType, endpointName, parameters)
268	if err != nil {
269		err = autorest.NewErrorWithError(err, "trafficmanager.EndpointsClient", "Update", nil, "Failure preparing request")
270		return
271	}
272
273	resp, err := client.UpdateSender(req)
274	if err != nil {
275		result.Response = autorest.Response{Response: resp}
276		err = autorest.NewErrorWithError(err, "trafficmanager.EndpointsClient", "Update", resp, "Failure sending request")
277		return
278	}
279
280	result, err = client.UpdateResponder(resp)
281	if err != nil {
282		err = autorest.NewErrorWithError(err, "trafficmanager.EndpointsClient", "Update", resp, "Failure responding to request")
283	}
284
285	return
286}
287
288// UpdatePreparer prepares the Update request.
289func (client EndpointsClient) UpdatePreparer(ctx context.Context, resourceGroupName string, profileName string, endpointType string, endpointName string, parameters Endpoint) (*http.Request, error) {
290	pathParameters := map[string]interface{}{
291		"endpointName":      autorest.Encode("path", endpointName),
292		"endpointType":      autorest.Encode("path", endpointType),
293		"profileName":       autorest.Encode("path", profileName),
294		"resourceGroupName": autorest.Encode("path", resourceGroupName),
295		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
296	}
297
298	const APIVersion = "2017-05-01"
299	queryParameters := map[string]interface{}{
300		"api-version": APIVersion,
301	}
302
303	preparer := autorest.CreatePreparer(
304		autorest.AsContentType("application/json; charset=utf-8"),
305		autorest.AsPatch(),
306		autorest.WithBaseURL(client.BaseURI),
307		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/trafficmanagerprofiles/{profileName}/{endpointType}/{endpointName}", pathParameters),
308		autorest.WithJSON(parameters),
309		autorest.WithQueryParameters(queryParameters))
310	return preparer.Prepare((&http.Request{}).WithContext(ctx))
311}
312
313// UpdateSender sends the Update request. The method will close the
314// http.Response Body if it receives an error.
315func (client EndpointsClient) UpdateSender(req *http.Request) (*http.Response, error) {
316	return autorest.SendWithSender(client, req,
317		azure.DoRetryWithRegistration(client.Client))
318}
319
320// UpdateResponder handles the response to the Update request. The method always
321// closes the http.Response Body.
322func (client EndpointsClient) UpdateResponder(resp *http.Response) (result Endpoint, err error) {
323	err = autorest.Respond(
324		resp,
325		client.ByInspecting(),
326		azure.WithErrorUnlessStatusCode(http.StatusOK),
327		autorest.ByUnmarshallingJSON(&result),
328		autorest.ByClosing())
329	result.Response = autorest.Response{Response: resp}
330	return
331}
332