| 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 | ) |
| 13 | |
| 14 | // Delete deletes the specified Queue within the specified Storage Account |
| 15 | func (client Client) Delete(ctx context.Context, accountName, queueName string) (result autorest.Response, err error) { |
| 16 | if accountName == "" { |
| 17 | return result, validation.NewError("queues.Client", "Delete", "`accountName` cannot be an empty string.") |
| 18 | } |
| 19 | if queueName == "" { |
| 20 | return result, validation.NewError("queues.Client", "Delete", "`queueName` cannot be an empty string.") |
| 21 | } |
| 22 | if strings.ToLower(queueName) != queueName { |
| 23 | return result, validation.NewError("queues.Client", "Delete", "`queueName` must be a lower-cased string.") |
| 24 | } |
| 25 | |
| 26 | req, err := client.DeletePreparer(ctx, accountName, queueName) |
| 27 | if err != nil { |
| 28 | err = autorest.NewErrorWithError(err, "queues.Client", "Delete", nil, "Failure preparing request") |
| 29 | return |
| 30 | } |
| 31 | |
| 32 | resp, err := client.DeleteSender(req) |
| 33 | if err != nil { |
| 34 | result = autorest.Response{Response: resp} |
| 35 | err = autorest.NewErrorWithError(err, "queues.Client", "Delete", resp, "Failure sending request") |
| 36 | return |
| 37 | } |
| 38 | |
| 39 | result, err = client.DeleteResponder(resp) |
| 40 | if err != nil { |
| 41 | err = autorest.NewErrorWithError(err, "queues.Client", "Delete", resp, "Failure responding to request") |
| 42 | return |
| 43 | } |
| 44 | |
| 45 | return |
| 46 | } |
| 47 | |
| 48 | // DeletePreparer prepares the Delete request. |
| 49 | func (client Client) DeletePreparer(ctx context.Context, accountName string, queueName string) (*http.Request, error) { |
| 50 | pathParameters := map[string]interface{}{ |
| 51 | "queueName": autorest.Encode("path", queueName), |
| 52 | } |
| 53 | |
| 54 | headers := map[string]interface{}{ |
| 55 | "x-ms-version": APIVersion, |
| 56 | } |
| 57 | |
| 58 | preparer := autorest.CreatePreparer( |
| 59 | autorest.AsContentType("application/xml; charset=utf-8"), |
| 60 | autorest.AsDelete(), |
| 61 | autorest.WithBaseURL(endpoints.GetQueueEndpoint(client.BaseURI, accountName)), |
| 62 | autorest.WithPathParameters("/{queueName}", pathParameters), |
| 63 | autorest.WithHeaders(headers)) |
| 64 | return preparer.Prepare((&http.Request{}).WithContext(ctx)) |
| 65 | } |
| 66 | |
| 67 | // DeleteSender sends the Delete request. The method will close the |
| 68 | // http.Response Body if it receives an error. |
| 69 | func (client Client) DeleteSender(req *http.Request) (*http.Response, error) { |
| 70 | return autorest.SendWithSender(client, req, |
| 71 | azure.DoRetryWithRegistration(client.Client)) |
| 72 | } |
| 73 | |
| 74 | // DeleteResponder handles the response to the Delete request. The method always |
| 75 | // closes the http.Response Body. |
| 76 | func (client Client) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { |
| 77 | err = autorest.Respond( |
| 78 | resp, |
| 79 | client.ByInspecting(), |
| 80 | azure.WithErrorUnlessStatusCode(http.StatusNoContent), |
| 81 | autorest.ByClosing()) |
| 82 | result = autorest.Response{Response: resp} |
| 83 | |
| 84 | return |
| 85 | } |