...

Source file src/github.com/Azure/azure-sdk-for-go/services/devtestlabs/mgmt/2018-09-15/dtl/galleryimages.go

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

View as plain text