Debian Codegraph @

storage/2018-11-09/blob/containers/delete.go

raw
1 package containers
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 marks the specified container for deletion.
14 // The container and any blobs contained within it are later deleted during garbage collection.
15 func (client Client) Delete(ctx context.Context, accountName, containerName string) (result autorest.Response, err error) {
16 if accountName == "" {
17 return result, validation.NewError("containers.Client", "Delete", "`accountName` cannot be an empty string.")
18 }
19 if containerName == "" {
20 return result, validation.NewError("containers.Client", "Delete", "`containerName` cannot be an empty string.")
21 }
22
23 req, err := client.DeletePreparer(ctx, accountName, containerName)
24 if err != nil {
25 err = autorest.NewErrorWithError(err, "containers.Client", "Delete", nil, "Failure preparing request")
26 return
27 }
28
29 resp, err := client.DeleteSender(req)
30 if err != nil {
31 err = autorest.NewErrorWithError(err, "containers.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, "containers.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 string, containerName string) (*http.Request, error) {
46 pathParameters := map[string]interface{}{
47 "containerName": autorest.Encode("path", containerName),
48 }
49
50 queryParameters := map[string]interface{}{
51 "restype": autorest.Encode("path", "container"),
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.GetBlobEndpoint(client.BaseURI, accountName)),
62 autorest.WithPathParameters("/{containerName}", pathParameters),
63 autorest.WithQueryParameters(queryParameters),
64 autorest.WithHeaders(headers))
65 return preparer.Prepare((&http.Request{}).WithContext(ctx))
66 }
67
68 // DeleteSender sends the Delete request. The method will close the
69 // http.Response Body if it receives an error.
70 func (client Client) DeleteSender(req *http.Request) (*http.Response, error) {
71 return autorest.SendWithSender(client, req,
72 azure.DoRetryWithRegistration(client.Client))
73 }
74
75 // DeleteResponder handles the response to the Delete request. The method always
76 // closes the http.Response Body.
77 func (client Client) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
78 err = autorest.Respond(
79 resp,
80 client.ByInspecting(),
81 azure.WithErrorUnlessStatusCode(http.StatusAccepted),
82 autorest.ByClosing())
83 result = autorest.Response{Response: resp}
84 return
85 }