Debian Codegraph @

storage/2020-08-04/table/tables/delete.go

raw
1 package tables
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 // Delete deletes the specified table and any data it contains.
14 func (client Client) Delete(ctx context.Context, accountName, tableName string) (result autorest.Response, err error) {
15 if accountName == "" {
16 return result, validation.NewError("tables.Client", "Delete", "`accountName` cannot be an empty string.")
17 }
18 if tableName == "" {
19 return result, validation.NewError("tables.Client", "Delete", "`tableName` cannot be an empty string.")
20 }
21
22 req, err := client.DeletePreparer(ctx, accountName, tableName)
23 if err != nil {
24 err = autorest.NewErrorWithError(err, "tables.Client", "Delete", nil, "Failure preparing request")
25 return
26 }
27
28 resp, err := client.DeleteSender(req)
29 if err != nil {
30 result = autorest.Response{Response: resp}
31 err = autorest.NewErrorWithError(err, "tables.Client", "Delete", resp, "Failure sending request")
32 return
33 }
34
35 result, err = client.DeleteResponder(resp)
36 if err != nil {
37 err = autorest.NewErrorWithError(err, "tables.Client", "Delete", resp, "Failure responding to request")
38 return
39 }
40
41 return
42 }
43
44 // DeletePreparer prepares the Delete request.
45 func (client Client) DeletePreparer(ctx context.Context, accountName, tableName string) (*http.Request, error) {
46 pathParameters := map[string]interface{}{
47 "tableName": autorest.Encode("path", tableName),
48 }
49
50 // NOTE: whilst the API documentation says that API Version is Optional
51 // apparently specifying it causes an "invalid content type" to always be returned
52 // as such we omit it here :shrug:
53
54 preparer := autorest.CreatePreparer(
55 autorest.AsDelete(),
56 autorest.WithBaseURL(endpoints.GetTableEndpoint(client.BaseURI, accountName)),
57 autorest.WithPathParameters("/Tables('{tableName}')", pathParameters))
58 return preparer.Prepare((&http.Request{}).WithContext(ctx))
59 }
60
61 // DeleteSender sends the Delete request. The method will close the
62 // http.Response Body if it receives an error.
63 func (client Client) DeleteSender(req *http.Request) (*http.Response, error) {
64 return autorest.SendWithSender(client, req,
65 azure.DoRetryWithRegistration(client.Client))
66 }
67
68 // DeleteResponder handles the response to the Delete request. The method always
69 // closes the http.Response Body.
70 func (client Client) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
71 err = autorest.Respond(
72 resp,
73 client.ByInspecting(),
74 azure.WithErrorUnlessStatusCode(http.StatusNoContent),
75 autorest.ByClosing())
76 result = autorest.Response{Response: resp}
77
78 return
79 }