| 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 |
type GetStatsResult struct { |
| 15 |
autorest.Response |
| 16 |
|
| 17 |
// The approximate size of the data stored on the share. |
| 18 |
// Note that this value may not include all recently created or recently resized files. |
| 19 |
ShareUsageBytes int64 `xml:"ShareUsageBytes"` |
| 20 |
} |
| 21 |
|
| 22 |
// GetStats returns information about the specified Storage Share |
| 23 |
func (client Client) GetStats(ctx context.Context, accountName, shareName string) (result GetStatsResult, err error) { |
| 24 |
if accountName == "" { |
| 25 |
return result, validation.NewError("shares.Client", "GetStats", "`accountName` cannot be an empty string.") |
| 26 |
} |
| 27 |
if shareName == "" { |
| 28 |
return result, validation.NewError("shares.Client", "GetStats", "`shareName` cannot be an empty string.") |
| 29 |
} |
| 30 |
if strings.ToLower(shareName) != shareName { |
| 31 |
return result, validation.NewError("shares.Client", "GetStats", "`shareName` must be a lower-cased string.") |
| 32 |
} |
| 33 |
|
| 34 |
req, err := client.GetStatsPreparer(ctx, accountName, shareName) |
| 35 |
if err != nil { |
| 36 |
err = autorest.NewErrorWithError(err, "shares.Client", "GetStats", nil, "Failure preparing request") |
| 37 |
return |
| 38 |
} |
| 39 |
|
| 40 |
resp, err := client.GetStatsSender(req) |
| 41 |
if err != nil { |
| 42 |
result.Response = autorest.Response{Response: resp} |
| 43 |
err = autorest.NewErrorWithError(err, "shares.Client", "GetStats", resp, "Failure sending request") |
| 44 |
return |
| 45 |
} |
| 46 |
|
| 47 |
result, err = client.GetStatsResponder(resp) |
| 48 |
if err != nil { |
| 49 |
err = autorest.NewErrorWithError(err, "shares.Client", "GetStats", resp, "Failure responding to request") |
| 50 |
return |
| 51 |
} |
| 52 |
|
| 53 |
return |
| 54 |
} |
| 55 |
|
| 56 |
// GetStatsPreparer prepares the GetStats request. |
| 57 |
func (client Client) GetStatsPreparer(ctx context.Context, accountName, shareName string) (*http.Request, error) { |
| 58 |
pathParameters := map[string]interface{}{ |
| 59 |
"shareName": autorest.Encode("path", shareName), |
| 60 |
} |
| 61 |
|
| 62 |
queryParameters := map[string]interface{}{ |
| 63 |
"restype": autorest.Encode("query", "share"), |
| 64 |
"comp": autorest.Encode("query", "stats"), |
| 65 |
} |
| 66 |
|
| 67 |
headers := map[string]interface{}{ |
| 68 |
"x-ms-version": APIVersion, |
| 69 |
} |
| 70 |
|
| 71 |
preparer := autorest.CreatePreparer( |
| 72 |
autorest.AsContentType("application/xml; charset=utf-8"), |
| 73 |
autorest.AsGet(), |
| 74 |
autorest.WithBaseURL(endpoints.GetFileEndpoint(client.BaseURI, accountName)), |
| 75 |
autorest.WithPathParameters("/{shareName}", pathParameters), |
| 76 |
autorest.WithQueryParameters(queryParameters), |
| 77 |
autorest.WithHeaders(headers)) |
| 78 |
return preparer.Prepare((&http.Request{}).WithContext(ctx)) |
| 79 |
} |
| 80 |
|
| 81 |
// GetStatsSender sends the GetStats request. The method will close the |
| 82 |
// http.Response Body if it receives an error. |
| 83 |
func (client Client) GetStatsSender(req *http.Request) (*http.Response, error) { |
| 84 |
return autorest.SendWithSender(client, req, |
| 85 |
azure.DoRetryWithRegistration(client.Client)) |
| 86 |
} |
| 87 |
|
| 88 |
// GetStatsResponder handles the response to the GetStats request. The method always |
| 89 |
// closes the http.Response Body. |
| 90 |
func (client Client) GetStatsResponder(resp *http.Response) (result GetStatsResult, err error) { |
| 91 |
err = autorest.Respond( |
| 92 |
resp, |
| 93 |
client.ByInspecting(), |
| 94 |
azure.WithErrorUnlessStatusCode(http.StatusOK), |
| 95 |
autorest.ByUnmarshallingXML(&result), |
| 96 |
autorest.ByClosing()) |
| 97 |
result.Response = autorest.Response{Response: resp} |
| 98 |
|
| 99 |
return |
| 100 |
} |