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// AvailableDelegationsClient is the network Client 18type AvailableDelegationsClient struct { 19 BaseClient 20} 21 22// NewAvailableDelegationsClient creates an instance of the AvailableDelegationsClient client. 23func NewAvailableDelegationsClient(subscriptionID string) AvailableDelegationsClient { 24 return NewAvailableDelegationsClientWithBaseURI(DefaultBaseURI, subscriptionID) 25} 26 27// NewAvailableDelegationsClientWithBaseURI creates an instance of the AvailableDelegationsClient 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 NewAvailableDelegationsClientWithBaseURI(baseURI string, subscriptionID string) AvailableDelegationsClient { 31 return AvailableDelegationsClient{NewWithBaseURI(baseURI, subscriptionID)} 32} 33 34// List gets all of the available subnet delegations for this subscription in this region. 35// Parameters: 36// location - the location of the subnet. 37func (client AvailableDelegationsClient) List(ctx context.Context, location string) (result AvailableDelegationsResultPage, err error) { 38 if tracing.IsEnabled() { 39 ctx = tracing.StartSpan(ctx, fqdn+"/AvailableDelegationsClient.List") 40 defer func() { 41 sc := -1 42 if result.adr.Response.Response != nil { 43 sc = result.adr.Response.Response.StatusCode 44 } 45 tracing.EndSpan(ctx, sc, err) 46 }() 47 } 48 result.fn = client.listNextResults 49 req, err := client.ListPreparer(ctx, location) 50 if err != nil { 51 err = autorest.NewErrorWithError(err, "network.AvailableDelegationsClient", "List", nil, "Failure preparing request") 52 return 53 } 54 55 resp, err := client.ListSender(req) 56 if err != nil { 57 result.adr.Response = autorest.Response{Response: resp} 58 err = autorest.NewErrorWithError(err, "network.AvailableDelegationsClient", "List", resp, "Failure sending request") 59 return 60 } 61 62 result.adr, err = client.ListResponder(resp) 63 if err != nil { 64 err = autorest.NewErrorWithError(err, "network.AvailableDelegationsClient", "List", resp, "Failure responding to request") 65 return 66 } 67 if result.adr.hasNextLink() && result.adr.IsEmpty() { 68 err = result.NextWithContext(ctx) 69 return 70 } 71 72 return 73} 74 75// ListPreparer prepares the List request. 76func (client AvailableDelegationsClient) ListPreparer(ctx context.Context, location string) (*http.Request, error) { 77 pathParameters := map[string]interface{}{ 78 "location": autorest.Encode("path", location), 79 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 80 } 81 82 const APIVersion = "2019-09-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}/providers/Microsoft.Network/locations/{location}/availableDelegations", pathParameters), 91 autorest.WithQueryParameters(queryParameters)) 92 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 93} 94 95// ListSender sends the List request. The method will close the 96// http.Response Body if it receives an error. 97func (client AvailableDelegationsClient) ListSender(req *http.Request) (*http.Response, error) { 98 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 99} 100 101// ListResponder handles the response to the List request. The method always 102// closes the http.Response Body. 103func (client AvailableDelegationsClient) ListResponder(resp *http.Response) (result AvailableDelegationsResult, 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// listNextResults retrieves the next set of results, if any. 114func (client AvailableDelegationsClient) listNextResults(ctx context.Context, lastResults AvailableDelegationsResult) (result AvailableDelegationsResult, err error) { 115 req, err := lastResults.availableDelegationsResultPreparer(ctx) 116 if err != nil { 117 return result, autorest.NewErrorWithError(err, "network.AvailableDelegationsClient", "listNextResults", nil, "Failure preparing next results request") 118 } 119 if req == nil { 120 return 121 } 122 resp, err := client.ListSender(req) 123 if err != nil { 124 result.Response = autorest.Response{Response: resp} 125 return result, autorest.NewErrorWithError(err, "network.AvailableDelegationsClient", "listNextResults", resp, "Failure sending next results request") 126 } 127 result, err = client.ListResponder(resp) 128 if err != nil { 129 err = autorest.NewErrorWithError(err, "network.AvailableDelegationsClient", "listNextResults", resp, "Failure responding to next results request") 130 } 131 return 132} 133 134// ListComplete enumerates all values, automatically crossing page boundaries as required. 135func (client AvailableDelegationsClient) ListComplete(ctx context.Context, location string) (result AvailableDelegationsResultIterator, err error) { 136 if tracing.IsEnabled() { 137 ctx = tracing.StartSpan(ctx, fqdn+"/AvailableDelegationsClient.List") 138 defer func() { 139 sc := -1 140 if result.Response().Response.Response != nil { 141 sc = result.page.Response().Response.Response.StatusCode 142 } 143 tracing.EndSpan(ctx, sc, err) 144 }() 145 } 146 result.page, err = client.List(ctx, location) 147 return 148} 149