| 1 | package queues |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "net/http" |
| 6 | |
| 7 | "github.com/Azure/go-autorest/autorest" |
| 8 | "github.com/Azure/go-autorest/autorest/azure" |
| 9 | "github.com/Azure/go-autorest/autorest/validation" |
| 10 | "github.com/tombuildsstuff/giovanni/storage/internal/endpoints" |
| 11 | ) |
| 12 | |
| 13 | type StorageServicePropertiesResponse struct { |
| 14 | StorageServiceProperties |
| 15 | autorest.Response |
| 16 | } |
| 17 | |
| 18 | // SetServiceProperties gets the properties for this queue |
| 19 | func (client Client) GetServiceProperties(ctx context.Context, accountName string) (result StorageServicePropertiesResponse, err error) { |
| 20 | if accountName == "" { |
| 21 | return result, validation.NewError("queues.Client", "GetServiceProperties", "`accountName` cannot be an empty string.") |
| 22 | } |
| 23 | |
| 24 | req, err := client.GetServicePropertiesPreparer(ctx, accountName) |
| 25 | if err != nil { |
| 26 | err = autorest.NewErrorWithError(err, "queues.Client", "GetServiceProperties", nil, "Failure preparing request") |
| 27 | return |
| 28 | } |
| 29 | |
| 30 | resp, err := client.GetServicePropertiesSender(req) |
| 31 | if err != nil { |
| 32 | result.Response = autorest.Response{Response: resp} |
| 33 | err = autorest.NewErrorWithError(err, "queues.Client", "GetServiceProperties", resp, "Failure sending request") |
| 34 | return |
| 35 | } |
| 36 | |
| 37 | result, err = client.GetServicePropertiesResponder(resp) |
| 38 | if err != nil { |
| 39 | err = autorest.NewErrorWithError(err, "queues.Client", "GetServiceProperties", resp, "Failure responding to request") |
| 40 | return |
| 41 | } |
| 42 | |
| 43 | return |
| 44 | } |
| 45 | |
| 46 | // GetServicePropertiesPreparer prepares the GetServiceProperties request. |
| 47 | func (client Client) GetServicePropertiesPreparer(ctx context.Context, accountName string) (*http.Request, error) { |
| 48 | queryParameters := map[string]interface{}{ |
| 49 | "comp": autorest.Encode("path", "properties"), |
| 50 | "restype": autorest.Encode("path", "service"), |
| 51 | } |
| 52 | |
| 53 | headers := map[string]interface{}{ |
| 54 | "x-ms-version": APIVersion, |
| 55 | } |
| 56 | |
| 57 | preparer := autorest.CreatePreparer( |
| 58 | autorest.AsContentType("application/xml; charset=utf-8"), |
| 59 | autorest.AsGet(), |
| 60 | autorest.WithBaseURL(endpoints.GetQueueEndpoint(client.BaseURI, accountName)), |
| 61 | autorest.WithPath("/"), |
| 62 | autorest.WithQueryParameters(queryParameters), |
| 63 | autorest.WithHeaders(headers)) |
| 64 | return preparer.Prepare((&http.Request{}).WithContext(ctx)) |
| 65 | } |
| 66 | |
| 67 | // GetServicePropertiesSender sends the GetServiceProperties request. The method will close the |
| 68 | // http.Response Body if it receives an error. |
| 69 | func (client Client) GetServicePropertiesSender(req *http.Request) (*http.Response, error) { |
| 70 | return autorest.SendWithSender(client, req, |
| 71 | azure.DoRetryWithRegistration(client.Client)) |
| 72 | } |
| 73 | |
| 74 | // GetServicePropertiesResponder handles the response to the GetServiceProperties request. The method always |
| 75 | // closes the http.Response Body. |
| 76 | func (client Client) GetServicePropertiesResponder(resp *http.Response) (result StorageServicePropertiesResponse, err error) { |
| 77 | err = autorest.Respond( |
| 78 | resp, |
| 79 | client.ByInspecting(), |
| 80 | azure.WithErrorUnlessStatusCode(http.StatusOK), |
| 81 | autorest.ByUnmarshallingXML(&result), |
| 82 | autorest.ByClosing()) |
| 83 | result.Response = autorest.Response{Response: resp} |
| 84 | |
| 85 | return |
| 86 | } |