1package apimanagement
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/autorest/validation"
25	"github.com/Azure/go-autorest/tracing"
26	"net/http"
27)
28
29// GatewayHostnameConfigurationClient is the apiManagement Client
30type GatewayHostnameConfigurationClient struct {
31	BaseClient
32}
33
34// NewGatewayHostnameConfigurationClient creates an instance of the GatewayHostnameConfigurationClient client.
35func NewGatewayHostnameConfigurationClient(subscriptionID string) GatewayHostnameConfigurationClient {
36	return NewGatewayHostnameConfigurationClientWithBaseURI(DefaultBaseURI, subscriptionID)
37}
38
39// NewGatewayHostnameConfigurationClientWithBaseURI creates an instance of the GatewayHostnameConfigurationClient
40// client using a custom endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI
41// (sovereign clouds, Azure stack).
42func NewGatewayHostnameConfigurationClientWithBaseURI(baseURI string, subscriptionID string) GatewayHostnameConfigurationClient {
43	return GatewayHostnameConfigurationClient{NewWithBaseURI(baseURI, subscriptionID)}
44}
45
46// CreateOrUpdate creates of updates hostname configuration for a Gateway.
47// Parameters:
48// resourceGroupName - the name of the resource group.
49// serviceName - the name of the API Management service.
50// gatewayID - gateway entity identifier. Must be unique in the current API Management service instance. Must
51// not have value 'managed'
52// hcID - gateway hostname configuration identifier. Must be unique in the scope of parent Gateway entity.
53// ifMatch - eTag of the Entity. Not required when creating an entity, but required when updating an entity.
54func (client GatewayHostnameConfigurationClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, serviceName string, gatewayID string, hcID string, parameters GatewayHostnameConfigurationContract, ifMatch string) (result GatewayHostnameConfigurationContract, err error) {
55	if tracing.IsEnabled() {
56		ctx = tracing.StartSpan(ctx, fqdn+"/GatewayHostnameConfigurationClient.CreateOrUpdate")
57		defer func() {
58			sc := -1
59			if result.Response.Response != nil {
60				sc = result.Response.Response.StatusCode
61			}
62			tracing.EndSpan(ctx, sc, err)
63		}()
64	}
65	if err := validation.Validate([]validation.Validation{
66		{TargetValue: serviceName,
67			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
68				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
69				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
70		{TargetValue: gatewayID,
71			Constraints: []validation.Constraint{{Target: "gatewayID", Name: validation.MaxLength, Rule: 80, Chain: nil},
72				{Target: "gatewayID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
73		{TargetValue: hcID,
74			Constraints: []validation.Constraint{{Target: "hcID", Name: validation.MaxLength, Rule: 80, Chain: nil},
75				{Target: "hcID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
76		return result, validation.NewError("apimanagement.GatewayHostnameConfigurationClient", "CreateOrUpdate", err.Error())
77	}
78
79	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, serviceName, gatewayID, hcID, parameters, ifMatch)
80	if err != nil {
81		err = autorest.NewErrorWithError(err, "apimanagement.GatewayHostnameConfigurationClient", "CreateOrUpdate", nil, "Failure preparing request")
82		return
83	}
84
85	resp, err := client.CreateOrUpdateSender(req)
86	if err != nil {
87		result.Response = autorest.Response{Response: resp}
88		err = autorest.NewErrorWithError(err, "apimanagement.GatewayHostnameConfigurationClient", "CreateOrUpdate", resp, "Failure sending request")
89		return
90	}
91
92	result, err = client.CreateOrUpdateResponder(resp)
93	if err != nil {
94		err = autorest.NewErrorWithError(err, "apimanagement.GatewayHostnameConfigurationClient", "CreateOrUpdate", resp, "Failure responding to request")
95		return
96	}
97
98	return
99}
100
101// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
102func (client GatewayHostnameConfigurationClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, gatewayID string, hcID string, parameters GatewayHostnameConfigurationContract, ifMatch string) (*http.Request, error) {
103	pathParameters := map[string]interface{}{
104		"gatewayId":         autorest.Encode("path", gatewayID),
105		"hcId":              autorest.Encode("path", hcID),
106		"resourceGroupName": autorest.Encode("path", resourceGroupName),
107		"serviceName":       autorest.Encode("path", serviceName),
108		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
109	}
110
111	const APIVersion = "2020-12-01"
112	queryParameters := map[string]interface{}{
113		"api-version": APIVersion,
114	}
115
116	preparer := autorest.CreatePreparer(
117		autorest.AsContentType("application/json; charset=utf-8"),
118		autorest.AsPut(),
119		autorest.WithBaseURL(client.BaseURI),
120		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/gateways/{gatewayId}/hostnameConfigurations/{hcId}", pathParameters),
121		autorest.WithJSON(parameters),
122		autorest.WithQueryParameters(queryParameters))
123	if len(ifMatch) > 0 {
124		preparer = autorest.DecoratePreparer(preparer,
125			autorest.WithHeader("If-Match", autorest.String(ifMatch)))
126	}
127	return preparer.Prepare((&http.Request{}).WithContext(ctx))
128}
129
130// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
131// http.Response Body if it receives an error.
132func (client GatewayHostnameConfigurationClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
133	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
134}
135
136// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
137// closes the http.Response Body.
138func (client GatewayHostnameConfigurationClient) CreateOrUpdateResponder(resp *http.Response) (result GatewayHostnameConfigurationContract, err error) {
139	err = autorest.Respond(
140		resp,
141		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
142		autorest.ByUnmarshallingJSON(&result),
143		autorest.ByClosing())
144	result.Response = autorest.Response{Response: resp}
145	return
146}
147
148// Delete deletes the specified hostname configuration from the specified Gateway.
149// Parameters:
150// resourceGroupName - the name of the resource group.
151// serviceName - the name of the API Management service.
152// gatewayID - gateway entity identifier. Must be unique in the current API Management service instance. Must
153// not have value 'managed'
154// hcID - gateway hostname configuration identifier. Must be unique in the scope of parent Gateway entity.
155// ifMatch - eTag of the Entity. ETag should match the current entity state from the header response of the GET
156// request or it should be * for unconditional update.
157func (client GatewayHostnameConfigurationClient) Delete(ctx context.Context, resourceGroupName string, serviceName string, gatewayID string, hcID string, ifMatch string) (result autorest.Response, err error) {
158	if tracing.IsEnabled() {
159		ctx = tracing.StartSpan(ctx, fqdn+"/GatewayHostnameConfigurationClient.Delete")
160		defer func() {
161			sc := -1
162			if result.Response != nil {
163				sc = result.Response.StatusCode
164			}
165			tracing.EndSpan(ctx, sc, err)
166		}()
167	}
168	if err := validation.Validate([]validation.Validation{
169		{TargetValue: serviceName,
170			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
171				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
172				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
173		{TargetValue: gatewayID,
174			Constraints: []validation.Constraint{{Target: "gatewayID", Name: validation.MaxLength, Rule: 80, Chain: nil},
175				{Target: "gatewayID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
176		{TargetValue: hcID,
177			Constraints: []validation.Constraint{{Target: "hcID", Name: validation.MaxLength, Rule: 80, Chain: nil},
178				{Target: "hcID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
179		return result, validation.NewError("apimanagement.GatewayHostnameConfigurationClient", "Delete", err.Error())
180	}
181
182	req, err := client.DeletePreparer(ctx, resourceGroupName, serviceName, gatewayID, hcID, ifMatch)
183	if err != nil {
184		err = autorest.NewErrorWithError(err, "apimanagement.GatewayHostnameConfigurationClient", "Delete", nil, "Failure preparing request")
185		return
186	}
187
188	resp, err := client.DeleteSender(req)
189	if err != nil {
190		result.Response = resp
191		err = autorest.NewErrorWithError(err, "apimanagement.GatewayHostnameConfigurationClient", "Delete", resp, "Failure sending request")
192		return
193	}
194
195	result, err = client.DeleteResponder(resp)
196	if err != nil {
197		err = autorest.NewErrorWithError(err, "apimanagement.GatewayHostnameConfigurationClient", "Delete", resp, "Failure responding to request")
198		return
199	}
200
201	return
202}
203
204// DeletePreparer prepares the Delete request.
205func (client GatewayHostnameConfigurationClient) DeletePreparer(ctx context.Context, resourceGroupName string, serviceName string, gatewayID string, hcID string, ifMatch string) (*http.Request, error) {
206	pathParameters := map[string]interface{}{
207		"gatewayId":         autorest.Encode("path", gatewayID),
208		"hcId":              autorest.Encode("path", hcID),
209		"resourceGroupName": autorest.Encode("path", resourceGroupName),
210		"serviceName":       autorest.Encode("path", serviceName),
211		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
212	}
213
214	const APIVersion = "2020-12-01"
215	queryParameters := map[string]interface{}{
216		"api-version": APIVersion,
217	}
218
219	preparer := autorest.CreatePreparer(
220		autorest.AsDelete(),
221		autorest.WithBaseURL(client.BaseURI),
222		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/gateways/{gatewayId}/hostnameConfigurations/{hcId}", pathParameters),
223		autorest.WithQueryParameters(queryParameters),
224		autorest.WithHeader("If-Match", autorest.String(ifMatch)))
225	return preparer.Prepare((&http.Request{}).WithContext(ctx))
226}
227
228// DeleteSender sends the Delete request. The method will close the
229// http.Response Body if it receives an error.
230func (client GatewayHostnameConfigurationClient) DeleteSender(req *http.Request) (*http.Response, error) {
231	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
232}
233
234// DeleteResponder handles the response to the Delete request. The method always
235// closes the http.Response Body.
236func (client GatewayHostnameConfigurationClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
237	err = autorest.Respond(
238		resp,
239		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
240		autorest.ByClosing())
241	result.Response = resp
242	return
243}
244
245// Get get details of a hostname configuration
246// Parameters:
247// resourceGroupName - the name of the resource group.
248// serviceName - the name of the API Management service.
249// gatewayID - gateway entity identifier. Must be unique in the current API Management service instance. Must
250// not have value 'managed'
251// hcID - gateway hostname configuration identifier. Must be unique in the scope of parent Gateway entity.
252func (client GatewayHostnameConfigurationClient) Get(ctx context.Context, resourceGroupName string, serviceName string, gatewayID string, hcID string) (result GatewayHostnameConfigurationContract, err error) {
253	if tracing.IsEnabled() {
254		ctx = tracing.StartSpan(ctx, fqdn+"/GatewayHostnameConfigurationClient.Get")
255		defer func() {
256			sc := -1
257			if result.Response.Response != nil {
258				sc = result.Response.Response.StatusCode
259			}
260			tracing.EndSpan(ctx, sc, err)
261		}()
262	}
263	if err := validation.Validate([]validation.Validation{
264		{TargetValue: serviceName,
265			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
266				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
267				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
268		{TargetValue: gatewayID,
269			Constraints: []validation.Constraint{{Target: "gatewayID", Name: validation.MaxLength, Rule: 80, Chain: nil},
270				{Target: "gatewayID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
271		{TargetValue: hcID,
272			Constraints: []validation.Constraint{{Target: "hcID", Name: validation.MaxLength, Rule: 80, Chain: nil},
273				{Target: "hcID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
274		return result, validation.NewError("apimanagement.GatewayHostnameConfigurationClient", "Get", err.Error())
275	}
276
277	req, err := client.GetPreparer(ctx, resourceGroupName, serviceName, gatewayID, hcID)
278	if err != nil {
279		err = autorest.NewErrorWithError(err, "apimanagement.GatewayHostnameConfigurationClient", "Get", nil, "Failure preparing request")
280		return
281	}
282
283	resp, err := client.GetSender(req)
284	if err != nil {
285		result.Response = autorest.Response{Response: resp}
286		err = autorest.NewErrorWithError(err, "apimanagement.GatewayHostnameConfigurationClient", "Get", resp, "Failure sending request")
287		return
288	}
289
290	result, err = client.GetResponder(resp)
291	if err != nil {
292		err = autorest.NewErrorWithError(err, "apimanagement.GatewayHostnameConfigurationClient", "Get", resp, "Failure responding to request")
293		return
294	}
295
296	return
297}
298
299// GetPreparer prepares the Get request.
300func (client GatewayHostnameConfigurationClient) GetPreparer(ctx context.Context, resourceGroupName string, serviceName string, gatewayID string, hcID string) (*http.Request, error) {
301	pathParameters := map[string]interface{}{
302		"gatewayId":         autorest.Encode("path", gatewayID),
303		"hcId":              autorest.Encode("path", hcID),
304		"resourceGroupName": autorest.Encode("path", resourceGroupName),
305		"serviceName":       autorest.Encode("path", serviceName),
306		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
307	}
308
309	const APIVersion = "2020-12-01"
310	queryParameters := map[string]interface{}{
311		"api-version": APIVersion,
312	}
313
314	preparer := autorest.CreatePreparer(
315		autorest.AsGet(),
316		autorest.WithBaseURL(client.BaseURI),
317		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/gateways/{gatewayId}/hostnameConfigurations/{hcId}", pathParameters),
318		autorest.WithQueryParameters(queryParameters))
319	return preparer.Prepare((&http.Request{}).WithContext(ctx))
320}
321
322// GetSender sends the Get request. The method will close the
323// http.Response Body if it receives an error.
324func (client GatewayHostnameConfigurationClient) GetSender(req *http.Request) (*http.Response, error) {
325	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
326}
327
328// GetResponder handles the response to the Get request. The method always
329// closes the http.Response Body.
330func (client GatewayHostnameConfigurationClient) GetResponder(resp *http.Response) (result GatewayHostnameConfigurationContract, err error) {
331	err = autorest.Respond(
332		resp,
333		azure.WithErrorUnlessStatusCode(http.StatusOK),
334		autorest.ByUnmarshallingJSON(&result),
335		autorest.ByClosing())
336	result.Response = autorest.Response{Response: resp}
337	return
338}
339
340// GetEntityTag checks that hostname configuration entity specified by identifier exists for specified Gateway entity.
341// Parameters:
342// resourceGroupName - the name of the resource group.
343// serviceName - the name of the API Management service.
344// gatewayID - gateway entity identifier. Must be unique in the current API Management service instance. Must
345// not have value 'managed'
346// hcID - gateway hostname configuration identifier. Must be unique in the scope of parent Gateway entity.
347func (client GatewayHostnameConfigurationClient) GetEntityTag(ctx context.Context, resourceGroupName string, serviceName string, gatewayID string, hcID string) (result autorest.Response, err error) {
348	if tracing.IsEnabled() {
349		ctx = tracing.StartSpan(ctx, fqdn+"/GatewayHostnameConfigurationClient.GetEntityTag")
350		defer func() {
351			sc := -1
352			if result.Response != nil {
353				sc = result.Response.StatusCode
354			}
355			tracing.EndSpan(ctx, sc, err)
356		}()
357	}
358	if err := validation.Validate([]validation.Validation{
359		{TargetValue: serviceName,
360			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
361				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
362				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
363		{TargetValue: gatewayID,
364			Constraints: []validation.Constraint{{Target: "gatewayID", Name: validation.MaxLength, Rule: 80, Chain: nil},
365				{Target: "gatewayID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
366		{TargetValue: hcID,
367			Constraints: []validation.Constraint{{Target: "hcID", Name: validation.MaxLength, Rule: 80, Chain: nil},
368				{Target: "hcID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
369		return result, validation.NewError("apimanagement.GatewayHostnameConfigurationClient", "GetEntityTag", err.Error())
370	}
371
372	req, err := client.GetEntityTagPreparer(ctx, resourceGroupName, serviceName, gatewayID, hcID)
373	if err != nil {
374		err = autorest.NewErrorWithError(err, "apimanagement.GatewayHostnameConfigurationClient", "GetEntityTag", nil, "Failure preparing request")
375		return
376	}
377
378	resp, err := client.GetEntityTagSender(req)
379	if err != nil {
380		result.Response = resp
381		err = autorest.NewErrorWithError(err, "apimanagement.GatewayHostnameConfigurationClient", "GetEntityTag", resp, "Failure sending request")
382		return
383	}
384
385	result, err = client.GetEntityTagResponder(resp)
386	if err != nil {
387		err = autorest.NewErrorWithError(err, "apimanagement.GatewayHostnameConfigurationClient", "GetEntityTag", resp, "Failure responding to request")
388		return
389	}
390
391	return
392}
393
394// GetEntityTagPreparer prepares the GetEntityTag request.
395func (client GatewayHostnameConfigurationClient) GetEntityTagPreparer(ctx context.Context, resourceGroupName string, serviceName string, gatewayID string, hcID string) (*http.Request, error) {
396	pathParameters := map[string]interface{}{
397		"gatewayId":         autorest.Encode("path", gatewayID),
398		"hcId":              autorest.Encode("path", hcID),
399		"resourceGroupName": autorest.Encode("path", resourceGroupName),
400		"serviceName":       autorest.Encode("path", serviceName),
401		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
402	}
403
404	const APIVersion = "2020-12-01"
405	queryParameters := map[string]interface{}{
406		"api-version": APIVersion,
407	}
408
409	preparer := autorest.CreatePreparer(
410		autorest.AsHead(),
411		autorest.WithBaseURL(client.BaseURI),
412		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/gateways/{gatewayId}/hostnameConfigurations/{hcId}", pathParameters),
413		autorest.WithQueryParameters(queryParameters))
414	return preparer.Prepare((&http.Request{}).WithContext(ctx))
415}
416
417// GetEntityTagSender sends the GetEntityTag request. The method will close the
418// http.Response Body if it receives an error.
419func (client GatewayHostnameConfigurationClient) GetEntityTagSender(req *http.Request) (*http.Response, error) {
420	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
421}
422
423// GetEntityTagResponder handles the response to the GetEntityTag request. The method always
424// closes the http.Response Body.
425func (client GatewayHostnameConfigurationClient) GetEntityTagResponder(resp *http.Response) (result autorest.Response, err error) {
426	err = autorest.Respond(
427		resp,
428		azure.WithErrorUnlessStatusCode(http.StatusOK),
429		autorest.ByClosing())
430	result.Response = resp
431	return
432}
433
434// ListByService lists the collection of hostname configurations for the specified gateway.
435// Parameters:
436// resourceGroupName - the name of the resource group.
437// serviceName - the name of the API Management service.
438// gatewayID - gateway entity identifier. Must be unique in the current API Management service instance. Must
439// not have value 'managed'
440// filter - |     Field     |     Usage     |     Supported operators     |     Supported functions
441// |</br>|-------------|-------------|-------------|-------------|</br>| name | filter | ge, le, eq, ne, gt, lt
442// | substringof, contains, startswith, endswith |</br>| hostname | filter | ge, le, eq, ne, gt, lt |
443// substringof, contains, startswith, endswith |</br>
444// top - number of records to return.
445// skip - number of records to skip.
446func (client GatewayHostnameConfigurationClient) ListByService(ctx context.Context, resourceGroupName string, serviceName string, gatewayID string, filter string, top *int32, skip *int32) (result GatewayHostnameConfigurationCollectionPage, err error) {
447	if tracing.IsEnabled() {
448		ctx = tracing.StartSpan(ctx, fqdn+"/GatewayHostnameConfigurationClient.ListByService")
449		defer func() {
450			sc := -1
451			if result.ghcc.Response.Response != nil {
452				sc = result.ghcc.Response.Response.StatusCode
453			}
454			tracing.EndSpan(ctx, sc, err)
455		}()
456	}
457	if err := validation.Validate([]validation.Validation{
458		{TargetValue: serviceName,
459			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
460				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
461				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
462		{TargetValue: gatewayID,
463			Constraints: []validation.Constraint{{Target: "gatewayID", Name: validation.MaxLength, Rule: 80, Chain: nil},
464				{Target: "gatewayID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
465		{TargetValue: top,
466			Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false,
467				Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil}}}}},
468		{TargetValue: skip,
469			Constraints: []validation.Constraint{{Target: "skip", Name: validation.Null, Rule: false,
470				Chain: []validation.Constraint{{Target: "skip", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil {
471		return result, validation.NewError("apimanagement.GatewayHostnameConfigurationClient", "ListByService", err.Error())
472	}
473
474	result.fn = client.listByServiceNextResults
475	req, err := client.ListByServicePreparer(ctx, resourceGroupName, serviceName, gatewayID, filter, top, skip)
476	if err != nil {
477		err = autorest.NewErrorWithError(err, "apimanagement.GatewayHostnameConfigurationClient", "ListByService", nil, "Failure preparing request")
478		return
479	}
480
481	resp, err := client.ListByServiceSender(req)
482	if err != nil {
483		result.ghcc.Response = autorest.Response{Response: resp}
484		err = autorest.NewErrorWithError(err, "apimanagement.GatewayHostnameConfigurationClient", "ListByService", resp, "Failure sending request")
485		return
486	}
487
488	result.ghcc, err = client.ListByServiceResponder(resp)
489	if err != nil {
490		err = autorest.NewErrorWithError(err, "apimanagement.GatewayHostnameConfigurationClient", "ListByService", resp, "Failure responding to request")
491		return
492	}
493	if result.ghcc.hasNextLink() && result.ghcc.IsEmpty() {
494		err = result.NextWithContext(ctx)
495		return
496	}
497
498	return
499}
500
501// ListByServicePreparer prepares the ListByService request.
502func (client GatewayHostnameConfigurationClient) ListByServicePreparer(ctx context.Context, resourceGroupName string, serviceName string, gatewayID string, filter string, top *int32, skip *int32) (*http.Request, error) {
503	pathParameters := map[string]interface{}{
504		"gatewayId":         autorest.Encode("path", gatewayID),
505		"resourceGroupName": autorest.Encode("path", resourceGroupName),
506		"serviceName":       autorest.Encode("path", serviceName),
507		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
508	}
509
510	const APIVersion = "2020-12-01"
511	queryParameters := map[string]interface{}{
512		"api-version": APIVersion,
513	}
514	if len(filter) > 0 {
515		queryParameters["$filter"] = autorest.Encode("query", filter)
516	}
517	if top != nil {
518		queryParameters["$top"] = autorest.Encode("query", *top)
519	}
520	if skip != nil {
521		queryParameters["$skip"] = autorest.Encode("query", *skip)
522	}
523
524	preparer := autorest.CreatePreparer(
525		autorest.AsGet(),
526		autorest.WithBaseURL(client.BaseURI),
527		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/gateways/{gatewayId}/hostnameConfigurations", pathParameters),
528		autorest.WithQueryParameters(queryParameters))
529	return preparer.Prepare((&http.Request{}).WithContext(ctx))
530}
531
532// ListByServiceSender sends the ListByService request. The method will close the
533// http.Response Body if it receives an error.
534func (client GatewayHostnameConfigurationClient) ListByServiceSender(req *http.Request) (*http.Response, error) {
535	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
536}
537
538// ListByServiceResponder handles the response to the ListByService request. The method always
539// closes the http.Response Body.
540func (client GatewayHostnameConfigurationClient) ListByServiceResponder(resp *http.Response) (result GatewayHostnameConfigurationCollection, err error) {
541	err = autorest.Respond(
542		resp,
543		azure.WithErrorUnlessStatusCode(http.StatusOK),
544		autorest.ByUnmarshallingJSON(&result),
545		autorest.ByClosing())
546	result.Response = autorest.Response{Response: resp}
547	return
548}
549
550// listByServiceNextResults retrieves the next set of results, if any.
551func (client GatewayHostnameConfigurationClient) listByServiceNextResults(ctx context.Context, lastResults GatewayHostnameConfigurationCollection) (result GatewayHostnameConfigurationCollection, err error) {
552	req, err := lastResults.gatewayHostnameConfigurationCollectionPreparer(ctx)
553	if err != nil {
554		return result, autorest.NewErrorWithError(err, "apimanagement.GatewayHostnameConfigurationClient", "listByServiceNextResults", nil, "Failure preparing next results request")
555	}
556	if req == nil {
557		return
558	}
559	resp, err := client.ListByServiceSender(req)
560	if err != nil {
561		result.Response = autorest.Response{Response: resp}
562		return result, autorest.NewErrorWithError(err, "apimanagement.GatewayHostnameConfigurationClient", "listByServiceNextResults", resp, "Failure sending next results request")
563	}
564	result, err = client.ListByServiceResponder(resp)
565	if err != nil {
566		err = autorest.NewErrorWithError(err, "apimanagement.GatewayHostnameConfigurationClient", "listByServiceNextResults", resp, "Failure responding to next results request")
567	}
568	return
569}
570
571// ListByServiceComplete enumerates all values, automatically crossing page boundaries as required.
572func (client GatewayHostnameConfigurationClient) ListByServiceComplete(ctx context.Context, resourceGroupName string, serviceName string, gatewayID string, filter string, top *int32, skip *int32) (result GatewayHostnameConfigurationCollectionIterator, err error) {
573	if tracing.IsEnabled() {
574		ctx = tracing.StartSpan(ctx, fqdn+"/GatewayHostnameConfigurationClient.ListByService")
575		defer func() {
576			sc := -1
577			if result.Response().Response.Response != nil {
578				sc = result.page.Response().Response.Response.StatusCode
579			}
580			tracing.EndSpan(ctx, sc, err)
581		}()
582	}
583	result.page, err = client.ListByService(ctx, resourceGroupName, serviceName, gatewayID, filter, top, skip)
584	return
585}
586