Debian Codegraph @

storage/2018-11-09/blob/blobs/put_page_clear.go

raw
1 package blobs
2
3 import (
4 "context"
5 "fmt"
6 "net/http"
7 "strings"
8
9 "github.com/Azure/go-autorest/autorest"
10 "github.com/Azure/go-autorest/autorest/azure"
11 "github.com/Azure/go-autorest/autorest/validation"
12 "github.com/tombuildsstuff/giovanni/storage/internal/endpoints"
13 )
14
15 type PutPageClearInput struct {
16 StartByte int64
17 EndByte int64
18
19 LeaseID *string
20 }
21
22 // PutPageClear clears a range of pages within a page blob.
23 func (client Client) PutPageClear(ctx context.Context, accountName, containerName, blobName string, input PutPageClearInput) (result autorest.Response, err error) {
24 if accountName == "" {
25 return result, validation.NewError("blobs.Client", "PutPageClear", "`accountName` cannot be an empty string.")
26 }
27 if containerName == "" {
28 return result, validation.NewError("blobs.Client", "PutPageClear", "`containerName` cannot be an empty string.")
29 }
30 if strings.ToLower(containerName) != containerName {
31 return result, validation.NewError("blobs.Client", "PutPageClear", "`containerName` must be a lower-cased string.")
32 }
33 if blobName == "" {
34 return result, validation.NewError("blobs.Client", "PutPageClear", "`blobName` cannot be an empty string.")
35 }
36 if input.StartByte < 0 {
37 return result, validation.NewError("blobs.Client", "PutPageClear", "`input.StartByte` must be greater than or equal to 0.")
38 }
39 if input.EndByte <= 0 {
40 return result, validation.NewError("blobs.Client", "PutPageClear", "`input.EndByte` must be greater than 0.")
41 }
42
43 req, err := client.PutPageClearPreparer(ctx, accountName, containerName, blobName, input)
44 if err != nil {
45 err = autorest.NewErrorWithError(err, "blobs.Client", "PutPageClear", nil, "Failure preparing request")
46 return
47 }
48
49 resp, err := client.PutPageClearSender(req)
50 if err != nil {
51 result = autorest.Response{Response: resp}
52 err = autorest.NewErrorWithError(err, "blobs.Client", "PutPageClear", resp, "Failure sending request")
53 return
54 }
55
56 result, err = client.PutPageClearResponder(resp)
57 if err != nil {
58 err = autorest.NewErrorWithError(err, "blobs.Client", "PutPageClear", resp, "Failure responding to request")
59 return
60 }
61
62 return
63 }
64
65 // PutPageClearPreparer prepares the PutPageClear request.
66 func (client Client) PutPageClearPreparer(ctx context.Context, accountName, containerName, blobName string, input PutPageClearInput) (*http.Request, error) {
67 pathParameters := map[string]interface{}{
68 "containerName": autorest.Encode("path", containerName),
69 "blobName": autorest.Encode("path", blobName),
70 }
71
72 queryParameters := map[string]interface{}{
73 "comp": autorest.Encode("query", "page"),
74 }
75
76 headers := map[string]interface{}{
77 "x-ms-version": APIVersion,
78 "x-ms-page-write": "clear",
79 "x-ms-range": fmt.Sprintf("bytes=%d-%d", input.StartByte, input.EndByte),
80 }
81
82 if input.LeaseID != nil {
83 headers["x-ms-lease-id"] = *input.LeaseID
84 }
85
86 preparer := autorest.CreatePreparer(
87 autorest.AsPut(),
88 autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)),
89 autorest.WithPathParameters("/{containerName}/{blobName}", pathParameters),
90 autorest.WithQueryParameters(queryParameters),
91 autorest.WithHeaders(headers))
92 return preparer.Prepare((&http.Request{}).WithContext(ctx))
93 }
94
95 // PutPageClearSender sends the PutPageClear request. The method will close the
96 // http.Response Body if it receives an error.
97 func (client Client) PutPageClearSender(req *http.Request) (*http.Response, error) {
98 return autorest.SendWithSender(client, req,
99 azure.DoRetryWithRegistration(client.Client))
100 }
101
102 // PutPageClearResponder handles the response to the PutPageClear request. The method always
103 // closes the http.Response Body.
104 func (client Client) PutPageClearResponder(resp *http.Response) (result autorest.Response, err error) {
105 err = autorest.Respond(
106 resp,
107 client.ByInspecting(),
108 azure.WithErrorUnlessStatusCode(http.StatusCreated),
109 autorest.ByClosing())
110 result = autorest.Response{Response: resp}
111
112 return
113 }