1package webpubsub 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// PrivateLinkResourcesClient is the REST API for Azure WebPubSub Service 18type PrivateLinkResourcesClient struct { 19 BaseClient 20} 21 22// NewPrivateLinkResourcesClient creates an instance of the PrivateLinkResourcesClient client. 23func NewPrivateLinkResourcesClient(subscriptionID string) PrivateLinkResourcesClient { 24 return NewPrivateLinkResourcesClientWithBaseURI(DefaultBaseURI, subscriptionID) 25} 26 27// NewPrivateLinkResourcesClientWithBaseURI creates an instance of the PrivateLinkResourcesClient client using a custom 28// endpoint. Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure 29// stack). 30func NewPrivateLinkResourcesClientWithBaseURI(baseURI string, subscriptionID string) PrivateLinkResourcesClient { 31 return PrivateLinkResourcesClient{NewWithBaseURI(baseURI, subscriptionID)} 32} 33 34// List get the private link resources that need to be created for a resource. 35// Parameters: 36// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value 37// from the Azure Resource Manager API or the portal. 38// resourceName - the name of the resource. 39func (client PrivateLinkResourcesClient) List(ctx context.Context, resourceGroupName string, resourceName string) (result PrivateLinkResourceListPage, err error) { 40 if tracing.IsEnabled() { 41 ctx = tracing.StartSpan(ctx, fqdn+"/PrivateLinkResourcesClient.List") 42 defer func() { 43 sc := -1 44 if result.plrl.Response.Response != nil { 45 sc = result.plrl.Response.Response.StatusCode 46 } 47 tracing.EndSpan(ctx, sc, err) 48 }() 49 } 50 result.fn = client.listNextResults 51 req, err := client.ListPreparer(ctx, resourceGroupName, resourceName) 52 if err != nil { 53 err = autorest.NewErrorWithError(err, "webpubsub.PrivateLinkResourcesClient", "List", nil, "Failure preparing request") 54 return 55 } 56 57 resp, err := client.ListSender(req) 58 if err != nil { 59 result.plrl.Response = autorest.Response{Response: resp} 60 err = autorest.NewErrorWithError(err, "webpubsub.PrivateLinkResourcesClient", "List", resp, "Failure sending request") 61 return 62 } 63 64 result.plrl, err = client.ListResponder(resp) 65 if err != nil { 66 err = autorest.NewErrorWithError(err, "webpubsub.PrivateLinkResourcesClient", "List", resp, "Failure responding to request") 67 return 68 } 69 if result.plrl.hasNextLink() && result.plrl.IsEmpty() { 70 err = result.NextWithContext(ctx) 71 return 72 } 73 74 return 75} 76 77// ListPreparer prepares the List request. 78func (client PrivateLinkResourcesClient) ListPreparer(ctx context.Context, resourceGroupName string, resourceName string) (*http.Request, error) { 79 pathParameters := map[string]interface{}{ 80 "resourceGroupName": autorest.Encode("path", resourceGroupName), 81 "resourceName": autorest.Encode("path", resourceName), 82 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 83 } 84 85 const APIVersion = "2021-04-01-preview" 86 queryParameters := map[string]interface{}{ 87 "api-version": APIVersion, 88 } 89 90 preparer := autorest.CreatePreparer( 91 autorest.AsGet(), 92 autorest.WithBaseURL(client.BaseURI), 93 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.SignalRService/webPubSub/{resourceName}/privateLinkResources", pathParameters), 94 autorest.WithQueryParameters(queryParameters)) 95 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 96} 97 98// ListSender sends the List request. The method will close the 99// http.Response Body if it receives an error. 100func (client PrivateLinkResourcesClient) ListSender(req *http.Request) (*http.Response, error) { 101 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 102} 103 104// ListResponder handles the response to the List request. The method always 105// closes the http.Response Body. 106func (client PrivateLinkResourcesClient) ListResponder(resp *http.Response) (result PrivateLinkResourceList, err error) { 107 err = autorest.Respond( 108 resp, 109 azure.WithErrorUnlessStatusCode(http.StatusOK), 110 autorest.ByUnmarshallingJSON(&result), 111 autorest.ByClosing()) 112 result.Response = autorest.Response{Response: resp} 113 return 114} 115 116// listNextResults retrieves the next set of results, if any. 117func (client PrivateLinkResourcesClient) listNextResults(ctx context.Context, lastResults PrivateLinkResourceList) (result PrivateLinkResourceList, err error) { 118 req, err := lastResults.privateLinkResourceListPreparer(ctx) 119 if err != nil { 120 return result, autorest.NewErrorWithError(err, "webpubsub.PrivateLinkResourcesClient", "listNextResults", nil, "Failure preparing next results request") 121 } 122 if req == nil { 123 return 124 } 125 resp, err := client.ListSender(req) 126 if err != nil { 127 result.Response = autorest.Response{Response: resp} 128 return result, autorest.NewErrorWithError(err, "webpubsub.PrivateLinkResourcesClient", "listNextResults", resp, "Failure sending next results request") 129 } 130 result, err = client.ListResponder(resp) 131 if err != nil { 132 err = autorest.NewErrorWithError(err, "webpubsub.PrivateLinkResourcesClient", "listNextResults", resp, "Failure responding to next results request") 133 } 134 return 135} 136 137// ListComplete enumerates all values, automatically crossing page boundaries as required. 138func (client PrivateLinkResourcesClient) ListComplete(ctx context.Context, resourceGroupName string, resourceName string) (result PrivateLinkResourceListIterator, err error) { 139 if tracing.IsEnabled() { 140 ctx = tracing.StartSpan(ctx, fqdn+"/PrivateLinkResourcesClient.List") 141 defer func() { 142 sc := -1 143 if result.Response().Response.Response != nil { 144 sc = result.page.Response().Response.Response.StatusCode 145 } 146 tracing.EndSpan(ctx, sc, err) 147 }() 148 } 149 result.page, err = client.List(ctx, resourceGroupName, resourceName) 150 return 151} 152