Debian Codegraph @

storage/2018-11-09/file/files/metadata_get.go

raw
1 package files
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 "github.com/tombuildsstuff/giovanni/storage/internal/metadata"
14 )
15
16 type GetMetaDataResult struct {
17 autorest.Response
18
19 MetaData map[string]string
20 }
21
22 // GetMetaData returns the MetaData for the specified File.
23 func (client Client) GetMetaData(ctx context.Context, accountName, shareName, path, fileName string) (result GetMetaDataResult, err error) {
24 if accountName == "" {
25 return result, validation.NewError("files.Client", "GetMetaData", "`accountName` cannot be an empty string.")
26 }
27 if shareName == "" {
28 return result, validation.NewError("files.Client", "GetMetaData", "`shareName` cannot be an empty string.")
29 }
30 if strings.ToLower(shareName) != shareName {
31 return result, validation.NewError("files.Client", "GetMetaData", "`shareName` must be a lower-cased string.")
32 }
33 if fileName == "" {
34 return result, validation.NewError("files.Client", "GetMetaData", "`fileName` cannot be an empty string.")
35 }
36
37 req, err := client.GetMetaDataPreparer(ctx, accountName, shareName, path, fileName)
38 if err != nil {
39 err = autorest.NewErrorWithError(err, "files.Client", "GetMetaData", nil, "Failure preparing request")
40 return
41 }
42
43 resp, err := client.GetMetaDataSender(req)
44 if err != nil {
45 result.Response = autorest.Response{Response: resp}
46 err = autorest.NewErrorWithError(err, "files.Client", "GetMetaData", resp, "Failure sending request")
47 return
48 }
49
50 result, err = client.GetMetaDataResponder(resp)
51 if err != nil {
52 err = autorest.NewErrorWithError(err, "files.Client", "GetMetaData", resp, "Failure responding to request")
53 return
54 }
55
56 return
57 }
58
59 // GetMetaDataPreparer prepares the GetMetaData request.
60 func (client Client) GetMetaDataPreparer(ctx context.Context, accountName, shareName, path, fileName string) (*http.Request, error) {
61 if path != "" {
62 path = fmt.Sprintf("%s/", path)
63 }
64 pathParameters := map[string]interface{}{
65 "shareName": autorest.Encode("path", shareName),
66 "directory": autorest.Encode("path", path),
67 "fileName": autorest.Encode("path", fileName),
68 }
69
70 queryParameters := map[string]interface{}{
71 "comp": autorest.Encode("query", "metadata"),
72 }
73
74 headers := map[string]interface{}{
75 "x-ms-version": APIVersion,
76 }
77
78 preparer := autorest.CreatePreparer(
79 autorest.AsContentType("application/xml; charset=utf-8"),
80 autorest.AsGet(),
81 autorest.WithBaseURL(endpoints.GetFileEndpoint(client.BaseURI, accountName)),
82 autorest.WithPathParameters("/{shareName}/{directory}{fileName}", pathParameters),
83 autorest.WithQueryParameters(queryParameters),
84 autorest.WithHeaders(headers))
85 return preparer.Prepare((&http.Request{}).WithContext(ctx))
86 }
87
88 // GetMetaDataSender sends the GetMetaData request. The method will close the
89 // http.Response Body if it receives an error.
90 func (client Client) GetMetaDataSender(req *http.Request) (*http.Response, error) {
91 return autorest.SendWithSender(client, req,
92 azure.DoRetryWithRegistration(client.Client))
93 }
94
95 // GetMetaDataResponder handles the response to the GetMetaData request. The method always
96 // closes the http.Response Body.
97 func (client Client) GetMetaDataResponder(resp *http.Response) (result GetMetaDataResult, err error) {
98 if resp != nil && resp.Header != nil {
99 result.MetaData = metadata.ParseFromHeaders(resp.Header)
100 }
101
102 err = autorest.Respond(
103 resp,
104 client.ByInspecting(),
105 azure.WithErrorUnlessStatusCode(http.StatusOK),
106 //metadata.ByParsingFromHeaders(&result.MetaData),
107 autorest.ByClosing())
108 result.Response = autorest.Response{Response: resp}
109
110 return
111 }