| 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 | // SetServiceProperties sets the properties for this queue |
| 14 | func (client Client) SetServiceProperties(ctx context.Context, accountName string, properties StorageServiceProperties) (result autorest.Response, err error) { |
| 15 | if accountName == "" { |
| 16 | return result, validation.NewError("queues.Client", "SetServiceProperties", "`accountName` cannot be an empty string.") |
| 17 | } |
| 18 | |
| 19 | req, err := client.SetServicePropertiesPreparer(ctx, accountName, properties) |
| 20 | if err != nil { |
| 21 | err = autorest.NewErrorWithError(err, "queues.Client", "SetServiceProperties", nil, "Failure preparing request") |
| 22 | return |
| 23 | } |
| 24 | |
| 25 | resp, err := client.SetServicePropertiesSender(req) |
| 26 | if err != nil { |
| 27 | result = autorest.Response{Response: resp} |
| 28 | err = autorest.NewErrorWithError(err, "queues.Client", "SetServiceProperties", resp, "Failure sending request") |
| 29 | return |
| 30 | } |
| 31 | |
| 32 | result, err = client.SetServicePropertiesResponder(resp) |
| 33 | if err != nil { |
| 34 | err = autorest.NewErrorWithError(err, "queues.Client", "SetServiceProperties", resp, "Failure responding to request") |
| 35 | return |
| 36 | } |
| 37 | |
| 38 | return |
| 39 | } |
| 40 | |
| 41 | // SetServicePropertiesPreparer prepares the SetServiceProperties request. |
| 42 | func (client Client) SetServicePropertiesPreparer(ctx context.Context, accountName string, properties StorageServiceProperties) (*http.Request, error) { |
| 43 | queryParameters := map[string]interface{}{ |
| 44 | "comp": autorest.Encode("path", "properties"), |
| 45 | "restype": autorest.Encode("path", "service"), |
| 46 | } |
| 47 | |
| 48 | headers := map[string]interface{}{ |
| 49 | "x-ms-version": APIVersion, |
| 50 | } |
| 51 | |
| 52 | preparer := autorest.CreatePreparer( |
| 53 | autorest.AsContentType("application/xml; charset=utf-8"), |
| 54 | autorest.AsPut(), |
| 55 | autorest.WithBaseURL(endpoints.GetQueueEndpoint(client.BaseURI, accountName)), |
| 56 | autorest.WithPath("/"), |
| 57 | autorest.WithQueryParameters(queryParameters), |
| 58 | autorest.WithXML(properties), |
| 59 | autorest.WithHeaders(headers)) |
| 60 | return preparer.Prepare((&http.Request{}).WithContext(ctx)) |
| 61 | } |
| 62 | |
| 63 | // SetServicePropertiesSender sends the SetServiceProperties request. The method will close the |
| 64 | // http.Response Body if it receives an error. |
| 65 | func (client Client) SetServicePropertiesSender(req *http.Request) (*http.Response, error) { |
| 66 | return autorest.SendWithSender(client, req, |
| 67 | azure.DoRetryWithRegistration(client.Client)) |
| 68 | } |
| 69 | |
| 70 | // SetServicePropertiesResponder handles the response to the SetServiceProperties request. The method always |
| 71 | // closes the http.Response Body. |
| 72 | func (client Client) SetServicePropertiesResponder(resp *http.Response) (result autorest.Response, err error) { |
| 73 | err = autorest.Respond( |
| 74 | resp, |
| 75 | client.ByInspecting(), |
| 76 | azure.WithErrorUnlessStatusCode(http.StatusAccepted), |
| 77 | autorest.ByClosing()) |
| 78 | result = autorest.Response{Response: resp} |
| 79 | |
| 80 | return |
| 81 | } |