1package apimanagement 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/autorest/validation" 14 "github.com/Azure/go-autorest/tracing" 15 "net/http" 16) 17 18// PortalSettingsClient is the apiManagement Client 19type PortalSettingsClient struct { 20 BaseClient 21} 22 23// NewPortalSettingsClient creates an instance of the PortalSettingsClient client. 24func NewPortalSettingsClient(subscriptionID string) PortalSettingsClient { 25 return NewPortalSettingsClientWithBaseURI(DefaultBaseURI, subscriptionID) 26} 27 28// NewPortalSettingsClientWithBaseURI creates an instance of the PortalSettingsClient client using a custom endpoint. 29// Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 30func NewPortalSettingsClientWithBaseURI(baseURI string, subscriptionID string) PortalSettingsClient { 31 return PortalSettingsClient{NewWithBaseURI(baseURI, subscriptionID)} 32} 33 34// ListByService lists a collection of portalsettings defined within a service instance.. 35// Parameters: 36// resourceGroupName - the name of the resource group. 37// serviceName - the name of the API Management service. 38func (client PortalSettingsClient) ListByService(ctx context.Context, resourceGroupName string, serviceName string) (result PortalSettingsCollection, err error) { 39 if tracing.IsEnabled() { 40 ctx = tracing.StartSpan(ctx, fqdn+"/PortalSettingsClient.ListByService") 41 defer func() { 42 sc := -1 43 if result.Response.Response != nil { 44 sc = result.Response.Response.StatusCode 45 } 46 tracing.EndSpan(ctx, sc, err) 47 }() 48 } 49 if err := validation.Validate([]validation.Validation{ 50 {TargetValue: serviceName, 51 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 52 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 53 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}}); err != nil { 54 return result, validation.NewError("apimanagement.PortalSettingsClient", "ListByService", err.Error()) 55 } 56 57 req, err := client.ListByServicePreparer(ctx, resourceGroupName, serviceName) 58 if err != nil { 59 err = autorest.NewErrorWithError(err, "apimanagement.PortalSettingsClient", "ListByService", nil, "Failure preparing request") 60 return 61 } 62 63 resp, err := client.ListByServiceSender(req) 64 if err != nil { 65 result.Response = autorest.Response{Response: resp} 66 err = autorest.NewErrorWithError(err, "apimanagement.PortalSettingsClient", "ListByService", resp, "Failure sending request") 67 return 68 } 69 70 result, err = client.ListByServiceResponder(resp) 71 if err != nil { 72 err = autorest.NewErrorWithError(err, "apimanagement.PortalSettingsClient", "ListByService", resp, "Failure responding to request") 73 return 74 } 75 76 return 77} 78 79// ListByServicePreparer prepares the ListByService request. 80func (client PortalSettingsClient) ListByServicePreparer(ctx context.Context, resourceGroupName string, serviceName string) (*http.Request, error) { 81 pathParameters := map[string]interface{}{ 82 "resourceGroupName": autorest.Encode("path", resourceGroupName), 83 "serviceName": autorest.Encode("path", serviceName), 84 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 85 } 86 87 const APIVersion = "2020-12-01" 88 queryParameters := map[string]interface{}{ 89 "api-version": APIVersion, 90 } 91 92 preparer := autorest.CreatePreparer( 93 autorest.AsGet(), 94 autorest.WithBaseURL(client.BaseURI), 95 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/portalsettings", pathParameters), 96 autorest.WithQueryParameters(queryParameters)) 97 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 98} 99 100// ListByServiceSender sends the ListByService request. The method will close the 101// http.Response Body if it receives an error. 102func (client PortalSettingsClient) ListByServiceSender(req *http.Request) (*http.Response, error) { 103 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 104} 105 106// ListByServiceResponder handles the response to the ListByService request. The method always 107// closes the http.Response Body. 108func (client PortalSettingsClient) ListByServiceResponder(resp *http.Response) (result PortalSettingsCollection, err error) { 109 err = autorest.Respond( 110 resp, 111 azure.WithErrorUnlessStatusCode(http.StatusOK), 112 autorest.ByUnmarshallingJSON(&result), 113 autorest.ByClosing()) 114 result.Response = autorest.Response{Response: resp} 115 return 116} 117