Debian Codegraph @

storage/2020-08-04/file/shares/delete.go

raw
1 package shares
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 Storage Share from within a Storage Account
15 func (client Client) Delete(ctx context.Context, accountName, shareName string, deleteSnapshots bool) (result autorest.Response, err error) {
16 if accountName == "" {
17 return result, validation.NewError("shares.Client", "Delete", "`accountName` cannot be an empty string.")
18 }
19 if shareName == "" {
20 return result, validation.NewError("shares.Client", "Delete", "`shareName` cannot be an empty string.")
21 }
22 if strings.ToLower(shareName) != shareName {
23 return result, validation.NewError("shares.Client", "Delete", "`shareName` must be a lower-cased string.")
24 }
25
26 req, err := client.DeletePreparer(ctx, accountName, shareName, deleteSnapshots)
27 if err != nil {
28 err = autorest.NewErrorWithError(err, "shares.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, "shares.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, "shares.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, shareName string, deleteSnapshots bool) (*http.Request, error) {
50 pathParameters := map[string]interface{}{
51 "shareName": autorest.Encode("path", shareName),
52 }
53
54 queryParameters := map[string]interface{}{
55 "restype": autorest.Encode("path", "share"),
56 }
57
58 headers := map[string]interface{}{
59 "x-ms-version": APIVersion,
60 }
61
62 if deleteSnapshots {
63 headers["x-ms-delete-snapshots"] = "include"
64 }
65
66 preparer := autorest.CreatePreparer(
67 autorest.AsContentType("application/xml; charset=utf-8"),
68 autorest.AsDelete(),
69 autorest.WithBaseURL(endpoints.GetFileEndpoint(client.BaseURI, accountName)),
70 autorest.WithPathParameters("/{shareName}", pathParameters),
71 autorest.WithQueryParameters(queryParameters),
72 autorest.WithHeaders(headers))
73 return preparer.Prepare((&http.Request{}).WithContext(ctx))
74 }
75
76 // DeleteSender sends the Delete request. The method will close the
77 // http.Response Body if it receives an error.
78 func (client Client) DeleteSender(req *http.Request) (*http.Response, error) {
79 return autorest.SendWithSender(client, req,
80 azure.DoRetryWithRegistration(client.Client))
81 }
82
83 // DeleteResponder handles the response to the Delete request. The method always
84 // closes the http.Response Body.
85 func (client Client) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
86 err = autorest.Respond(
87 resp,
88 client.ByInspecting(),
89 azure.WithErrorUnlessStatusCode(http.StatusAccepted),
90 autorest.ByClosing())
91 result = autorest.Response{Response: resp}
92
93 return
94 }