1 package dtl
2
3
4
5
6
7
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
18 type GalleryImageClient struct {
19 BaseClient
20 }
21
22
23 func NewGalleryImageClient(subscriptionID string) GalleryImageClient {
24 return NewGalleryImageClientWithBaseURI(DefaultBaseURI, subscriptionID)
25 }
26
27
28
29 func NewGalleryImageClientWithBaseURI(baseURI string, subscriptionID string) GalleryImageClient {
30 return GalleryImageClient{NewWithBaseURI(baseURI, subscriptionID)}
31 }
32
33
34
35
36
37
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
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
107
108 func (client GalleryImageClient) ListSender(req *http.Request) (*http.Response, error) {
109 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
110 }
111
112
113
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
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
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