...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/devtestlabs/mgmt/2015-05-21-preview/dtl/galleryimage.go

Documentation: github.com/Azure/azure-sdk-for-go/services/preview/devtestlabs/mgmt/2015-05-21-preview/dtl

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

View as plain text