Debian Codegraph @

storage/2017-07-29/queue/queues/metadata_get.go

raw
1 package queues
2
3 import (
4 "context"
5 "net/http"
6 "strings"
7
8 "github.com/Azure/go-autorest/autorest"
9 "github.com/Azure/go-autorest/autorest/azure"
10 "github.com/Azure/go-autorest/autorest/validation"
11 "github.com/tombuildsstuff/giovanni/storage/internal/endpoints"
12 "github.com/tombuildsstuff/giovanni/storage/internal/metadata"
13 )
14
15 type GetMetaDataResult struct {
16 autorest.Response
17
18 MetaData map[string]string
19 }
20
21 // GetMetaData returns the metadata for this Queue
22 func (client Client) GetMetaData(ctx context.Context, accountName, queueName string) (result GetMetaDataResult, err error) {
23 if accountName == "" {
24 return result, validation.NewError("queues.Client", "GetMetaData", "`accountName` cannot be an empty string.")
25 }
26 if queueName == "" {
27 return result, validation.NewError("queues.Client", "GetMetaData", "`queueName` cannot be an empty string.")
28 }
29 if strings.ToLower(queueName) != queueName {
30 return result, validation.NewError("queues.Client", "GetMetaData", "`queueName` must be a lower-cased string.")
31 }
32
33 req, err := client.GetMetaDataPreparer(ctx, accountName, queueName)
34 if err != nil {
35 err = autorest.NewErrorWithError(err, "queues.Client", "GetMetaData", nil, "Failure preparing request")
36 return
37 }
38
39 resp, err := client.GetMetaDataSender(req)
40 if err != nil {
41 result.Response = autorest.Response{Response: resp}
42 err = autorest.NewErrorWithError(err, "queues.Client", "GetMetaData", resp, "Failure sending request")
43 return
44 }
45
46 result, err = client.GetMetaDataResponder(resp)
47 if err != nil {
48 err = autorest.NewErrorWithError(err, "queues.Client", "GetMetaData", resp, "Failure responding to request")
49 return
50 }
51
52 return
53 }
54
55 // GetMetaDataPreparer prepares the GetMetaData request.
56 func (client Client) GetMetaDataPreparer(ctx context.Context, accountName, queueName string) (*http.Request, error) {
57 pathParameters := map[string]interface{}{
58 "queueName": autorest.Encode("path", queueName),
59 }
60
61 queryParameters := map[string]interface{}{
62 "comp": autorest.Encode("path", "metadata"),
63 }
64
65 headers := map[string]interface{}{
66 "x-ms-version": APIVersion,
67 }
68
69 preparer := autorest.CreatePreparer(
70 autorest.AsContentType("application/xml; charset=utf-8"),
71 autorest.AsGet(),
72 autorest.WithBaseURL(endpoints.GetQueueEndpoint(client.BaseURI, accountName)),
73 autorest.WithPathParameters("/{queueName}", pathParameters),
74 autorest.WithQueryParameters(queryParameters),
75 autorest.WithHeaders(headers))
76 return preparer.Prepare((&http.Request{}).WithContext(ctx))
77 }
78
79 // GetMetaDataSender sends the GetMetaData request. The method will close the
80 // http.Response Body if it receives an error.
81 func (client Client) GetMetaDataSender(req *http.Request) (*http.Response, error) {
82 return autorest.SendWithSender(client, req,
83 azure.DoRetryWithRegistration(client.Client))
84 }
85
86 // GetMetaDataResponder handles the response to the GetMetaData request. The method always
87 // closes the http.Response Body.
88 func (client Client) GetMetaDataResponder(resp *http.Response) (result GetMetaDataResult, err error) {
89 if resp != nil {
90 result.MetaData = metadata.ParseFromHeaders(resp.Header)
91 }
92
93 err = autorest.Respond(
94 resp,
95 client.ByInspecting(),
96 azure.WithErrorUnlessStatusCode(http.StatusOK),
97 autorest.ByClosing())
98 result.Response = autorest.Response{Response: resp}
99
100 return
101 }