| 1 | package messages |
| 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 a specific message |
| 15 | func (client Client) Delete(ctx context.Context, accountName, queueName, messageID, popReceipt string) (result autorest.Response, err error) { |
| 16 | if accountName == "" { |
| 17 | return result, validation.NewError("messages.Client", "Delete", "`accountName` cannot be an empty string.") |
| 18 | } |
| 19 | if queueName == "" { |
| 20 | return result, validation.NewError("messages.Client", "Delete", "`queueName` cannot be an empty string.") |
| 21 | } |
| 22 | if strings.ToLower(queueName) != queueName { |
| 23 | return result, validation.NewError("messages.Client", "Delete", "`queueName` must be a lower-cased string.") |
| 24 | } |
| 25 | if messageID == "" { |
| 26 | return result, validation.NewError("messages.Client", "Delete", "`messageID` cannot be an empty string.") |
| 27 | } |
| 28 | if popReceipt == "" { |
| 29 | return result, validation.NewError("messages.Client", "Delete", "`popReceipt` cannot be an empty string.") |
| 30 | } |
| 31 | |
| 32 | req, err := client.DeletePreparer(ctx, accountName, queueName, messageID, popReceipt) |
| 33 | if err != nil { |
| 34 | err = autorest.NewErrorWithError(err, "messages.Client", "Delete", nil, "Failure preparing request") |
| 35 | return |
| 36 | } |
| 37 | |
| 38 | resp, err := client.DeleteSender(req) |
| 39 | if err != nil { |
| 40 | result = autorest.Response{Response: resp} |
| 41 | err = autorest.NewErrorWithError(err, "messages.Client", "Delete", resp, "Failure sending request") |
| 42 | return |
| 43 | } |
| 44 | |
| 45 | result, err = client.DeleteResponder(resp) |
| 46 | if err != nil { |
| 47 | err = autorest.NewErrorWithError(err, "messages.Client", "Delete", resp, "Failure responding to request") |
| 48 | return |
| 49 | } |
| 50 | |
| 51 | return |
| 52 | } |
| 53 | |
| 54 | // DeletePreparer prepares the Delete request. |
| 55 | func (client Client) DeletePreparer(ctx context.Context, accountName, queueName, messageID, popReceipt string) (*http.Request, error) { |
| 56 | pathParameters := map[string]interface{}{ |
| 57 | "queueName": autorest.Encode("path", queueName), |
| 58 | "messageID": autorest.Encode("path", messageID), |
| 59 | } |
| 60 | |
| 61 | queryParameters := map[string]interface{}{ |
| 62 | "popreceipt": autorest.Encode("query", popReceipt), |
| 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.AsDelete(), |
| 72 | autorest.WithBaseURL(endpoints.GetQueueEndpoint(client.BaseURI, accountName)), |
| 73 | autorest.WithPathParameters("/{queueName}/messages/{messageID}", pathParameters), |
| 74 | autorest.WithQueryParameters(queryParameters), |
| 75 | autorest.WithHeaders(headers)) |
| 76 | return preparer.Prepare((&http.Request{}).WithContext(ctx)) |
| 77 | } |
| 78 | |
| 79 | // DeleteSender sends the Delete request. The method will close the |
| 80 | // http.Response Body if it receives an error. |
| 81 | func (client Client) DeleteSender(req *http.Request) (*http.Response, error) { |
| 82 | return autorest.SendWithSender(client, req, |
| 83 | azure.DoRetryWithRegistration(client.Client)) |
| 84 | } |
| 85 | |
| 86 | // DeleteResponder handles the response to the Delete request. The method always |
| 87 | // closes the http.Response Body. |
| 88 | func (client Client) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { |
| 89 | err = autorest.Respond( |
| 90 | resp, |
| 91 | client.ByInspecting(), |
| 92 | azure.WithErrorUnlessStatusCode(http.StatusNoContent), |
| 93 | autorest.ByClosing()) |
| 94 | result = autorest.Response{Response: resp} |
| 95 | |
| 96 | return |
| 97 | } |