1package datashare 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// ConsumerSourceDataSetsClient is the creates a Microsoft.DataShare management client. 18type ConsumerSourceDataSetsClient struct { 19 BaseClient 20} 21 22// NewConsumerSourceDataSetsClient creates an instance of the ConsumerSourceDataSetsClient client. 23func NewConsumerSourceDataSetsClient(subscriptionID string) ConsumerSourceDataSetsClient { 24 return NewConsumerSourceDataSetsClientWithBaseURI(DefaultBaseURI, subscriptionID) 25} 26 27// NewConsumerSourceDataSetsClientWithBaseURI creates an instance of the ConsumerSourceDataSetsClient client using a 28// custom endpoint. Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, 29// Azure stack). 30func NewConsumerSourceDataSetsClientWithBaseURI(baseURI string, subscriptionID string) ConsumerSourceDataSetsClient { 31 return ConsumerSourceDataSetsClient{NewWithBaseURI(baseURI, subscriptionID)} 32} 33 34// ListByShareSubscription get source dataSets of a shareSubscription 35// Parameters: 36// resourceGroupName - the resource group name. 37// accountName - the name of the share account. 38// shareSubscriptionName - the name of the shareSubscription. 39// skipToken - continuation token 40func (client ConsumerSourceDataSetsClient) ListByShareSubscription(ctx context.Context, resourceGroupName string, accountName string, shareSubscriptionName string, skipToken string) (result ConsumerSourceDataSetListPage, err error) { 41 if tracing.IsEnabled() { 42 ctx = tracing.StartSpan(ctx, fqdn+"/ConsumerSourceDataSetsClient.ListByShareSubscription") 43 defer func() { 44 sc := -1 45 if result.csdsl.Response.Response != nil { 46 sc = result.csdsl.Response.Response.StatusCode 47 } 48 tracing.EndSpan(ctx, sc, err) 49 }() 50 } 51 result.fn = client.listByShareSubscriptionNextResults 52 req, err := client.ListByShareSubscriptionPreparer(ctx, resourceGroupName, accountName, shareSubscriptionName, skipToken) 53 if err != nil { 54 err = autorest.NewErrorWithError(err, "datashare.ConsumerSourceDataSetsClient", "ListByShareSubscription", nil, "Failure preparing request") 55 return 56 } 57 58 resp, err := client.ListByShareSubscriptionSender(req) 59 if err != nil { 60 result.csdsl.Response = autorest.Response{Response: resp} 61 err = autorest.NewErrorWithError(err, "datashare.ConsumerSourceDataSetsClient", "ListByShareSubscription", resp, "Failure sending request") 62 return 63 } 64 65 result.csdsl, err = client.ListByShareSubscriptionResponder(resp) 66 if err != nil { 67 err = autorest.NewErrorWithError(err, "datashare.ConsumerSourceDataSetsClient", "ListByShareSubscription", resp, "Failure responding to request") 68 return 69 } 70 if result.csdsl.hasNextLink() && result.csdsl.IsEmpty() { 71 err = result.NextWithContext(ctx) 72 return 73 } 74 75 return 76} 77 78// ListByShareSubscriptionPreparer prepares the ListByShareSubscription request. 79func (client ConsumerSourceDataSetsClient) ListByShareSubscriptionPreparer(ctx context.Context, resourceGroupName string, accountName string, shareSubscriptionName string, skipToken string) (*http.Request, error) { 80 pathParameters := map[string]interface{}{ 81 "accountName": autorest.Encode("path", accountName), 82 "resourceGroupName": autorest.Encode("path", resourceGroupName), 83 "shareSubscriptionName": autorest.Encode("path", shareSubscriptionName), 84 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 85 } 86 87 const APIVersion = "2018-11-01-preview" 88 queryParameters := map[string]interface{}{ 89 "api-version": APIVersion, 90 } 91 if len(skipToken) > 0 { 92 queryParameters["$skipToken"] = autorest.Encode("query", skipToken) 93 } 94 95 preparer := autorest.CreatePreparer( 96 autorest.AsGet(), 97 autorest.WithBaseURL(client.BaseURI), 98 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataShare/accounts/{accountName}/shareSubscriptions/{shareSubscriptionName}/ConsumerSourceDataSets", pathParameters), 99 autorest.WithQueryParameters(queryParameters)) 100 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 101} 102 103// ListByShareSubscriptionSender sends the ListByShareSubscription request. The method will close the 104// http.Response Body if it receives an error. 105func (client ConsumerSourceDataSetsClient) ListByShareSubscriptionSender(req *http.Request) (*http.Response, error) { 106 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 107} 108 109// ListByShareSubscriptionResponder handles the response to the ListByShareSubscription request. The method always 110// closes the http.Response Body. 111func (client ConsumerSourceDataSetsClient) ListByShareSubscriptionResponder(resp *http.Response) (result ConsumerSourceDataSetList, err error) { 112 err = autorest.Respond( 113 resp, 114 azure.WithErrorUnlessStatusCode(http.StatusOK), 115 autorest.ByUnmarshallingJSON(&result), 116 autorest.ByClosing()) 117 result.Response = autorest.Response{Response: resp} 118 return 119} 120 121// listByShareSubscriptionNextResults retrieves the next set of results, if any. 122func (client ConsumerSourceDataSetsClient) listByShareSubscriptionNextResults(ctx context.Context, lastResults ConsumerSourceDataSetList) (result ConsumerSourceDataSetList, err error) { 123 req, err := lastResults.consumerSourceDataSetListPreparer(ctx) 124 if err != nil { 125 return result, autorest.NewErrorWithError(err, "datashare.ConsumerSourceDataSetsClient", "listByShareSubscriptionNextResults", nil, "Failure preparing next results request") 126 } 127 if req == nil { 128 return 129 } 130 resp, err := client.ListByShareSubscriptionSender(req) 131 if err != nil { 132 result.Response = autorest.Response{Response: resp} 133 return result, autorest.NewErrorWithError(err, "datashare.ConsumerSourceDataSetsClient", "listByShareSubscriptionNextResults", resp, "Failure sending next results request") 134 } 135 result, err = client.ListByShareSubscriptionResponder(resp) 136 if err != nil { 137 err = autorest.NewErrorWithError(err, "datashare.ConsumerSourceDataSetsClient", "listByShareSubscriptionNextResults", resp, "Failure responding to next results request") 138 } 139 return 140} 141 142// ListByShareSubscriptionComplete enumerates all values, automatically crossing page boundaries as required. 143func (client ConsumerSourceDataSetsClient) ListByShareSubscriptionComplete(ctx context.Context, resourceGroupName string, accountName string, shareSubscriptionName string, skipToken string) (result ConsumerSourceDataSetListIterator, err error) { 144 if tracing.IsEnabled() { 145 ctx = tracing.StartSpan(ctx, fqdn+"/ConsumerSourceDataSetsClient.ListByShareSubscription") 146 defer func() { 147 sc := -1 148 if result.Response().Response.Response != nil { 149 sc = result.page.Response().Response.Response.StatusCode 150 } 151 tracing.EndSpan(ctx, sc, err) 152 }() 153 } 154 result.page, err = client.ListByShareSubscription(ctx, resourceGroupName, accountName, shareSubscriptionName, skipToken) 155 return 156} 157