diff --git a/storage/2020-08-04/queue/queues/models.go b/storage/2020-08-04/queue/queues/models.go index 2195244..fbbbce9 100644 --- a/storage/2020-08-04/queue/queues/models.go +++ b/storage/2020-08-04/queue/queues/models.go @@ -36,7 +36,7 @@ type Cors struct { type CorsRule struct { AllowedOrigins string `xml:"AllowedOrigins"` AllowedMethods string `xml:"AllowedMethods"` - AllowedHeaders string `xml:"AllowedHeaders` + AllowedHeaders string `xml:"AllowedHeaders"` ExposedHeaders string `xml:"ExposedHeaders"` MaxAgeInSeconds int `xml:"MaxAgeInSeconds"` } diff --git a/storage/2023-11-03/blob/accounts/get_service_properties.go b/storage/2023-11-03/blob/accounts/get_service_properties.go index 01ea987..fce040b 100644 --- a/storage/2023-11-03/blob/accounts/get_service_properties.go +++ b/storage/2023-11-03/blob/accounts/get_service_properties.go @@ -9,13 +9,13 @@ import ( ) type GetServicePropertiesResult struct { - HttpResponse *client.Response - Model *StorageServiceProperties + StorageServiceProperties + HttpResponse *http.Response } -func (c Client) GetServiceProperties(ctx context.Context, accountName string) (resp GetServicePropertiesResult, err error) { +func (c Client) GetServiceProperties(ctx context.Context, accountName string) (result GetServicePropertiesResult, err error) { if accountName == "" { - return resp, fmt.Errorf("`accountName` cannot be an empty string") + return result, fmt.Errorf("`accountName` cannot be an empty string") } opts := client.RequestOptions{ @@ -27,23 +27,28 @@ func (c Client) GetServiceProperties(ctx context.Context, accountName string) (r OptionsObject: servicePropertiesOptions{}, Path: "/", } + req, err := c.Client.NewRequest(ctx, opts) if err != nil { err = fmt.Errorf("building request: %+v", err) return } - resp.HttpResponse, err = req.Execute(ctx) - if err != nil { - err = fmt.Errorf("executing request: %+v", err) - return - } - if resp.HttpResponse != nil { - if err = resp.HttpResponse.Unmarshal(&resp.Model); err != nil { - err = fmt.Errorf("unmarshaling response: %+v", err) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + + err = resp.Unmarshal(&result) + if err != nil { + err = fmt.Errorf("unmarshalling response: %+v", err) return } } + if err != nil { + err = fmt.Errorf("executing request: %+v", err) + return + } return } diff --git a/storage/2023-11-03/blob/accounts/set_service_properties.go b/storage/2023-11-03/blob/accounts/set_service_properties.go index 173a80f..5252dc0 100644 --- a/storage/2023-11-03/blob/accounts/set_service_properties.go +++ b/storage/2023-11-03/blob/accounts/set_service_properties.go @@ -9,12 +9,12 @@ import ( ) type SetServicePropertiesResult struct { - HttpResponse *client.Response + HttpResponse *http.Response } -func (c Client) SetServiceProperties(ctx context.Context, accountName string, input StorageServiceProperties) (resp SetServicePropertiesResult, err error) { +func (c Client) SetServiceProperties(ctx context.Context, accountName string, input StorageServiceProperties) (result SetServicePropertiesResult, err error) { if accountName == "" { - return resp, fmt.Errorf("`accountName` cannot be an empty string") + return result, fmt.Errorf("`accountName` cannot be an empty string") } opts := client.RequestOptions{ @@ -26,16 +26,23 @@ func (c Client) SetServiceProperties(ctx context.Context, accountName string, in OptionsObject: servicePropertiesOptions{}, Path: "/", } + req, err := c.Client.NewRequest(ctx, opts) if err != nil { err = fmt.Errorf("building request: %+v", err) return } + if err = req.Marshal(&input); err != nil { err = fmt.Errorf("marshaling request: %+v", err) return } - resp.HttpResponse, err = req.Execute(ctx) + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return diff --git a/storage/2023-11-03/blob/accounts/set_service_properties_test.go b/storage/2023-11-03/blob/accounts/set_service_properties_test.go index 0e642fc..6e2d8c1 100644 --- a/storage/2023-11-03/blob/accounts/set_service_properties_test.go +++ b/storage/2023-11-03/blob/accounts/set_service_properties_test.go @@ -79,12 +79,12 @@ func TestContainerLifecycle(t *testing.T) { t.Fatal(fmt.Errorf("error getting properties: %s", err)) } - website := result.Model.StaticWebsite + website := result.StaticWebsite if website.Enabled != true { t.Fatalf("Expected the StaticWebsite %t but got %t", true, website.Enabled) } - logging := result.Model.Logging + logging := result.Logging if logging.Version != "2.0" { t.Fatalf("Expected the Logging Version %s but got %s", "2.0", logging.Version) } diff --git a/storage/2023-11-03/blob/blobs/README.md b/storage/2023-11-03/blob/blobs/README.md index f1a23a5..276ddc3 100644 --- a/storage/2023-11-03/blob/blobs/README.md +++ b/storage/2023-11-03/blob/blobs/README.md @@ -30,7 +30,7 @@ func Example() error { blobClient, err := blobs.NewWithBaseUri(fmt.Sprintf("https://%s.blob.%s", accountName, domainSuffix)) if err != nil { - return fmt.Errorf("building client for environment: %+v", err) + return fmt.Errorf("building client for environment: %v", err) } auth, err := auth.NewSharedKeyAuthorizer(accountName, storageAccountKey, auth.SharedKey) diff --git a/storage/2023-11-03/blob/blobs/append_block.go b/storage/2023-11-03/blob/blobs/append_block.go index a1068d4..e3f638e 100644 --- a/storage/2023-11-03/blob/blobs/append_block.go +++ b/storage/2023-11-03/blob/blobs/append_block.go @@ -46,7 +46,7 @@ type AppendBlockInput struct { } type AppendBlockResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response BlobAppendOffset string BlobCommittedBlockCount int64 @@ -56,22 +56,25 @@ type AppendBlockResponse struct { } // AppendBlock commits a new block of data to the end of an existing append blob. -func (c Client) AppendBlock(ctx context.Context, containerName, blobName string, input AppendBlockInput) (resp AppendBlockResponse, err error) { - +func (c Client) AppendBlock(ctx context.Context, containerName, blobName string, input AppendBlockInput) (result AppendBlockResponse, err error) { if containerName == "" { - return resp, fmt.Errorf("`containerName` cannot be an empty string") + err = fmt.Errorf("`containerName` cannot be an empty string") + return } if strings.ToLower(containerName) != containerName { - return resp, fmt.Errorf("`containerName` must be a lower-cased string") + err = fmt.Errorf("`containerName` must be a lower-cased string") + return } if blobName == "" { - return resp, fmt.Errorf("`blobName` cannot be an empty string") + err = fmt.Errorf("`blobName` cannot be an empty string") + return } if input.Content != nil && len(*input.Content) > (4*1024*1024) { - return resp, fmt.Errorf("`input.Content` must be at most 4MB") + err = fmt.Errorf("`input.Content` must be at most 4MB") + return } opts := client.RequestOptions{ @@ -97,30 +100,31 @@ func (c Client) AppendBlock(ctx context.Context, containerName, blobName string, req.ContentLength = int64(len(*input.Content)) - resp.HttpResponse, err = req.Execute(ctx) - if err != nil { - err = fmt.Errorf("executing request: %+v", err) - return - } + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response - if resp.HttpResponse != nil { - if resp.HttpResponse.Header != nil { - resp.BlobAppendOffset = resp.HttpResponse.Header.Get("x-ms-blob-append-offset") - resp.ContentMD5 = resp.HttpResponse.Header.Get("Content-MD5") - resp.ETag = resp.HttpResponse.Header.Get("ETag") - resp.LastModified = resp.HttpResponse.Header.Get("Last-Modified") + if resp.Header != nil { + result.BlobAppendOffset = resp.Header.Get("x-ms-blob-append-offset") + result.ContentMD5 = resp.Header.Get("Content-MD5") + result.ETag = resp.Header.Get("ETag") + result.LastModified = resp.Header.Get("Last-Modified") - if v := resp.HttpResponse.Header.Get("x-ms-blob-committed-block-count"); v != "" { + if v := resp.Header.Get("x-ms-blob-committed-block-count"); v != "" { i, innerErr := strconv.Atoi(v) if innerErr != nil { - err = fmt.Errorf("error parsing %q as an integer: %s", v, innerErr) + err = fmt.Errorf("parsing `x-ms-blob-committed-block-count` header value %q: %+v", v, innerErr) return } - resp.BlobCommittedBlockCount = int64(i) + result.BlobCommittedBlockCount = int64(i) } - } } + if err != nil { + err = fmt.Errorf("executing request: %+v", err) + return + } return } diff --git a/storage/2023-11-03/blob/blobs/blob_page_test.go b/storage/2023-11-03/blob/blobs/blob_page_test.go index e812dc4..6bfb19d 100644 --- a/storage/2023-11-03/blob/blobs/blob_page_test.go +++ b/storage/2023-11-03/blob/blobs/blob_page_test.go @@ -42,7 +42,7 @@ func TestPageBlobLifecycle(t *testing.T) { t.Fatalf("building client for environment: %+v", err) } - if err := client.PrepareWithSharedKeyAuth(containersClient.Client, testData, auth.SharedKey); err != nil { + if err = client.PrepareWithSharedKeyAuth(containersClient.Client, testData, auth.SharedKey); err != nil { t.Fatalf("adding authorizer to client: %+v", err) } @@ -57,7 +57,7 @@ func TestPageBlobLifecycle(t *testing.T) { t.Fatalf("building client for environment: %+v", err) } - if err := client.PrepareWithSharedKeyAuth(blobClient.Client, testData, auth.SharedKey); err != nil { + if err = client.PrepareWithSharedKeyAuth(blobClient.Client, testData, auth.SharedKey); err != nil { t.Fatalf("adding authorizer to client: %+v", err) } diff --git a/storage/2023-11-03/blob/blobs/copy.go b/storage/2023-11-03/blob/blobs/copy.go index 2ff309c..3687c10 100644 --- a/storage/2023-11-03/blob/blobs/copy.go +++ b/storage/2023-11-03/blob/blobs/copy.go @@ -106,29 +106,28 @@ type CopyInput struct { } type CopyResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response CopyID string CopyStatus string } // Copy copies a blob to a destination within the storage account asynchronously. -func (c Client) Copy(ctx context.Context, containerName, blobName string, input CopyInput) (resp CopyResponse, err error) { - +func (c Client) Copy(ctx context.Context, containerName, blobName string, input CopyInput) (result CopyResponse, err error) { if containerName == "" { - return resp, fmt.Errorf("`containerName` cannot be an empty string") + return result, fmt.Errorf("`containerName` cannot be an empty string") } if strings.ToLower(containerName) != containerName { - return resp, fmt.Errorf("`containerName` must be a lower-cased string") + return result, fmt.Errorf("`containerName` must be a lower-cased string") } if blobName == "" { - return resp, fmt.Errorf("`blobName` cannot be an empty string") + return result, fmt.Errorf("`blobName` cannot be an empty string") } if input.CopySource == "" { - return resp, fmt.Errorf("`input.CopySource` cannot be an empty string") + return result, fmt.Errorf("`input.CopySource` cannot be an empty string") } opts := client.RequestOptions{ @@ -148,19 +147,21 @@ func (c Client) Copy(ctx context.Context, containerName, blobName string, input return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + + if resp.Header != nil { + result.CopyID = resp.Header.Get("x-ms-copy-id") + result.CopyStatus = resp.Header.Get("x-ms-copy-status") + } + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return } - if resp.HttpResponse != nil { - if resp.HttpResponse.Header != nil { - resp.CopyID = resp.HttpResponse.Header.Get("x-ms-copy-id") - resp.CopyStatus = resp.HttpResponse.Header.Get("x-ms-copy-status") - } - } - return } diff --git a/storage/2023-11-03/blob/blobs/copy_abort.go b/storage/2023-11-03/blob/blobs/copy_abort.go index 064c56f..5d9469a 100644 --- a/storage/2023-11-03/blob/blobs/copy_abort.go +++ b/storage/2023-11-03/blob/blobs/copy_abort.go @@ -20,26 +20,29 @@ type AbortCopyInput struct { } type CopyAbortResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response } // AbortCopy aborts a pending Copy Blob operation, and leaves a destination blob with zero length and full metadata. -func (c Client) AbortCopy(ctx context.Context, containerName, blobName string, input AbortCopyInput) (resp CopyAbortResponse, err error) { - +func (c Client) AbortCopy(ctx context.Context, containerName, blobName string, input AbortCopyInput) (result CopyAbortResponse, err error) { if containerName == "" { - return resp, fmt.Errorf("`containerName` cannot be an empty string") + err = fmt.Errorf("`containerName` cannot be an empty string") + return } if strings.ToLower(containerName) != containerName { - return resp, fmt.Errorf("`containerName` must be a lower-cased string") + err = fmt.Errorf("`containerName` must be a lower-cased string") + return } if blobName == "" { - return resp, fmt.Errorf("`blobName` cannot be an empty string") + err = fmt.Errorf("`blobName` cannot be an empty string") + return } if input.CopyID == "" { - return resp, fmt.Errorf("`input.CopyID` cannot be an empty string") + err = fmt.Errorf("`input.CopyID` cannot be an empty string") + return } opts := client.RequestOptions{ @@ -59,7 +62,11 @@ func (c Client) AbortCopy(ctx context.Context, containerName, blobName string, i return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return diff --git a/storage/2023-11-03/blob/blobs/copy_test.go b/storage/2023-11-03/blob/blobs/copy_test.go index 022ba26..6f4c7b5 100644 --- a/storage/2023-11-03/blob/blobs/copy_test.go +++ b/storage/2023-11-03/blob/blobs/copy_test.go @@ -43,7 +43,7 @@ func TestCopyFromExistingFile(t *testing.T) { t.Fatalf("building client for environment: %+v", err) } - if err := client.PrepareWithSharedKeyAuth(containersClient.Client, testData, auth.SharedKey); err != nil { + if err = client.PrepareWithSharedKeyAuth(containersClient.Client, testData, auth.SharedKey); err != nil { t.Fatalf("adding authorizer to client: %+v", err) } @@ -59,7 +59,7 @@ func TestCopyFromExistingFile(t *testing.T) { t.Fatalf("building client for environment: %+v", err) } - if err := client.PrepareWithSharedKeyAuth(blobClient.Client, testData, auth.SharedKey); err != nil { + if err = client.PrepareWithSharedKeyAuth(blobClient.Client, testData, auth.SharedKey); err != nil { t.Fatalf("adding authorizer to client: %+v", err) } @@ -137,7 +137,7 @@ func TestCopyFromURL(t *testing.T) { t.Fatalf("building client for environment: %+v", err) } - if err := client.PrepareWithSharedKeyAuth(containersClient.Client, testData, auth.SharedKey); err != nil { + if err = client.PrepareWithSharedKeyAuth(containersClient.Client, testData, auth.SharedKey); err != nil { t.Fatalf("adding authorizer to client: %+v", err) } @@ -152,7 +152,7 @@ func TestCopyFromURL(t *testing.T) { t.Fatalf("building client for environment: %+v", err) } - if err := client.PrepareWithSharedKeyAuth(blobClient.Client, testData, auth.SharedKey); err != nil { + if err = client.PrepareWithSharedKeyAuth(blobClient.Client, testData, auth.SharedKey); err != nil { t.Fatalf("adding authorizer to client: %+v", err) } diff --git a/storage/2023-11-03/blob/blobs/delete.go b/storage/2023-11-03/blob/blobs/delete.go index e13aaa5..80c1e43 100644 --- a/storage/2023-11-03/blob/blobs/delete.go +++ b/storage/2023-11-03/blob/blobs/delete.go @@ -21,22 +21,21 @@ type DeleteInput struct { } type DeleteResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response } // Delete marks the specified blob or snapshot for deletion. The blob is later deleted during garbage collection. -func (c Client) Delete(ctx context.Context, containerName, blobName string, input DeleteInput) (resp DeleteResponse, err error) { - +func (c Client) Delete(ctx context.Context, containerName, blobName string, input DeleteInput) (result DeleteResponse, err error) { if containerName == "" { - return resp, fmt.Errorf("`containerName` cannot be an empty string") + return result, fmt.Errorf("`containerName` cannot be an empty string") } if strings.ToLower(containerName) != containerName { - return resp, fmt.Errorf("`containerName` must be a lower-cased string") + return result, fmt.Errorf("`containerName` must be a lower-cased string") } if blobName == "" { - return resp, fmt.Errorf("`blobName` cannot be an empty string") + return result, fmt.Errorf("`blobName` cannot be an empty string") } opts := client.RequestOptions{ @@ -56,7 +55,11 @@ func (c Client) Delete(ctx context.Context, containerName, blobName string, inpu return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return diff --git a/storage/2023-11-03/blob/blobs/delete_snapshot.go b/storage/2023-11-03/blob/blobs/delete_snapshot.go index 0407eb1..e5cfa3c 100644 --- a/storage/2023-11-03/blob/blobs/delete_snapshot.go +++ b/storage/2023-11-03/blob/blobs/delete_snapshot.go @@ -20,26 +20,29 @@ type DeleteSnapshotInput struct { } type DeleteSnapshotResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response } // DeleteSnapshot marks a single Snapshot of a Blob for Deletion based on it's DateTime, which will be deleted during the next Garbage Collection cycle. -func (c Client) DeleteSnapshot(ctx context.Context, containerName, blobName string, input DeleteSnapshotInput) (resp DeleteSnapshotResponse, err error) { - +func (c Client) DeleteSnapshot(ctx context.Context, containerName, blobName string, input DeleteSnapshotInput) (result DeleteSnapshotResponse, err error) { if containerName == "" { - return resp, fmt.Errorf("`containerName` cannot be an empty string") + err = fmt.Errorf("`containerName` cannot be an empty string") + return } if strings.ToLower(containerName) != containerName { - return resp, fmt.Errorf("`containerName` must be a lower-cased string") + err = fmt.Errorf("`containerName` must be a lower-cased string") + return } if blobName == "" { - return resp, fmt.Errorf("`blobName` cannot be an empty string") + err = fmt.Errorf("`blobName` cannot be an empty string") + return } if input.SnapshotDateTime == "" { - return resp, fmt.Errorf("`input.SnapshotDateTime` cannot be an empty string") + err = fmt.Errorf("`input.SnapshotDateTime` cannot be an empty string") + return } opts := client.RequestOptions{ @@ -59,7 +62,11 @@ func (c Client) DeleteSnapshot(ctx context.Context, containerName, blobName stri return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return diff --git a/storage/2023-11-03/blob/blobs/delete_snapshots.go b/storage/2023-11-03/blob/blobs/delete_snapshots.go index 34b3beb..dd0ce7b 100644 --- a/storage/2023-11-03/blob/blobs/delete_snapshots.go +++ b/storage/2023-11-03/blob/blobs/delete_snapshots.go @@ -17,22 +17,24 @@ type DeleteSnapshotsInput struct { } type DeleteSnapshotsResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response } // DeleteSnapshots marks all Snapshots of a Blob for Deletion, which will be deleted during the next Garbage Collection Cycle. -func (c Client) DeleteSnapshots(ctx context.Context, containerName, blobName string, input DeleteSnapshotsInput) (resp DeleteSnapshotsResponse, err error) { - +func (c Client) DeleteSnapshots(ctx context.Context, containerName, blobName string, input DeleteSnapshotsInput) (result DeleteSnapshotsResponse, err error) { if containerName == "" { - return resp, fmt.Errorf("`containerName` cannot be an empty string") + err = fmt.Errorf("`containerName` cannot be an empty string") + return } if strings.ToLower(containerName) != containerName { - return resp, fmt.Errorf("`containerName` must be a lower-cased string") + err = fmt.Errorf("`containerName` must be a lower-cased string") + return } if blobName == "" { - return resp, fmt.Errorf("`blobName` cannot be an empty string") + err = fmt.Errorf("`blobName` cannot be an empty string") + return } opts := client.RequestOptions{ @@ -52,7 +54,11 @@ func (c Client) DeleteSnapshots(ctx context.Context, containerName, blobName str return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return diff --git a/storage/2023-11-03/blob/blobs/get.go b/storage/2023-11-03/blob/blobs/get.go index 0f5572a..c108a32 100644 --- a/storage/2023-11-03/blob/blobs/get.go +++ b/storage/2023-11-03/blob/blobs/get.go @@ -17,32 +17,31 @@ type GetInput struct { } type GetResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response Contents []byte } // Get reads or downloads a blob from the system, including its metadata and properties. -func (c Client) Get(ctx context.Context, containerName, blobName string, input GetInput) (resp GetResponse, err error) { - +func (c Client) Get(ctx context.Context, containerName, blobName string, input GetInput) (result GetResponse, err error) { if containerName == "" { - return resp, fmt.Errorf("`containerName` cannot be an empty string") + return result, fmt.Errorf("`containerName` cannot be an empty string") } if strings.ToLower(containerName) != containerName { - return resp, fmt.Errorf("`containerName` must be a lower-cased string") + return result, fmt.Errorf("`containerName` must be a lower-cased string") } if blobName == "" { - return resp, fmt.Errorf("`blobName` cannot be an empty string") + return result, fmt.Errorf("`blobName` cannot be an empty string") } if input.LeaseID != nil && *input.LeaseID == "" { - return resp, fmt.Errorf("`input.LeaseID` should either be specified or nil, not an empty string") + return result, fmt.Errorf("`input.LeaseID` should either be specified or nil, not an empty string") } if (input.StartByte != nil && input.EndByte == nil) || input.StartByte == nil && input.EndByte != nil { - return resp, fmt.Errorf("`input.StartByte` and `input.EndByte` must both be specified, or both be nil") + return result, fmt.Errorf("`input.StartByte` and `input.EndByte` must both be specified, or both be nil") } opts := client.RequestOptions{ @@ -63,18 +62,21 @@ func (c Client) Get(ctx context.Context, containerName, blobName string, input G return } - resp.HttpResponse, err = req.Execute(ctx) - if err != nil { - err = fmt.Errorf("executing request: %+v", err) - return - } + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response - if resp.HttpResponse != nil { - err = resp.HttpResponse.Unmarshal(&resp.Contents) + err = resp.Unmarshal(&result.Contents) if err != nil { - return resp, fmt.Errorf("unmarshalling response: %v", err) + err = fmt.Errorf("unmarshalling response: %+v", err) + return } } + if err != nil { + err = fmt.Errorf("executing request: %+v", err) + return + } return } diff --git a/storage/2023-11-03/blob/blobs/get_block_list.go b/storage/2023-11-03/blob/blobs/get_block_list.go index 9a783cb..b7c4037 100644 --- a/storage/2023-11-03/blob/blobs/get_block_list.go +++ b/storage/2023-11-03/blob/blobs/get_block_list.go @@ -17,7 +17,7 @@ type GetBlockListInput struct { } type GetBlockListResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response // The size of the blob in bytes BlobContentLength *int64 @@ -36,18 +36,17 @@ type GetBlockListResponse struct { } // GetBlockList retrieves the list of blocks that have been uploaded as part of a block blob. -func (c Client) GetBlockList(ctx context.Context, containerName, blobName string, input GetBlockListInput) (resp GetBlockListResponse, err error) { - +func (c Client) GetBlockList(ctx context.Context, containerName, blobName string, input GetBlockListInput) (result GetBlockListResponse, err error) { if containerName == "" { - return resp, fmt.Errorf("`containerName` cannot be an empty string") + return result, fmt.Errorf("`containerName` cannot be an empty string") } if strings.ToLower(containerName) != containerName { - return resp, fmt.Errorf("`containerName` must be a lower-cased string") + return result, fmt.Errorf("`containerName` must be a lower-cased string") } if blobName == "" { - return resp, fmt.Errorf("`blobName` cannot be an empty string") + return result, fmt.Errorf("`blobName` cannot be an empty string") } opts := client.RequestOptions{ @@ -67,33 +66,37 @@ func (c Client) GetBlockList(ctx context.Context, containerName, blobName string return } - resp.HttpResponse, err = req.Execute(ctx) - if err != nil { - err = fmt.Errorf("executing request: %+v", err) - return - } + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response - if resp.HttpResponse != nil { - if resp.HttpResponse.Header != nil { - resp.ContentType = resp.HttpResponse.Header.Get("Content-Type") - resp.ETag = resp.HttpResponse.Header.Get("ETag") + if resp.Header != nil { + result.ContentType = resp.Header.Get("Content-Type") + result.ETag = resp.Header.Get("ETag") - if v := resp.HttpResponse.Header.Get("x-ms-blob-content-length"); v != "" { + if v := resp.Header.Get("x-ms-blob-content-length"); v != "" { i, innerErr := strconv.Atoi(v) if innerErr != nil { - err = fmt.Errorf("error parsing %q as an integer: %s", v, innerErr) + err = fmt.Errorf("parsing `x-ms-blob-content-length` header value %q: %s", v, innerErr) return } i64 := int64(i) - resp.BlobContentLength = &i64 + result.BlobContentLength = &i64 } } - err = resp.HttpResponse.Unmarshal(&resp) + + err = resp.Unmarshal(&result) if err != nil { - return resp, fmt.Errorf("unmarshalling response: %v", err) + err = fmt.Errorf("unmarshalling response: %+v", err) + return } } + if err != nil { + err = fmt.Errorf("executing request: %+v", err) + return + } return } diff --git a/storage/2023-11-03/blob/blobs/get_page_ranges.go b/storage/2023-11-03/blob/blobs/get_page_ranges.go index 6d0f541..fe83294 100644 --- a/storage/2023-11-03/blob/blobs/get_page_ranges.go +++ b/storage/2023-11-03/blob/blobs/get_page_ranges.go @@ -19,7 +19,7 @@ type GetPageRangesInput struct { } type GetPageRangesResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response // The size of the blob in bytes ContentLength *int64 @@ -42,22 +42,21 @@ type PageRange struct { } // GetPageRanges returns the list of valid page ranges for a page blob or snapshot of a page blob. -func (c Client) GetPageRanges(ctx context.Context, containerName, blobName string, input GetPageRangesInput) (resp GetPageRangesResponse, err error) { - +func (c Client) GetPageRanges(ctx context.Context, containerName, blobName string, input GetPageRangesInput) (result GetPageRangesResponse, err error) { if containerName == "" { - return resp, fmt.Errorf("`containerName` cannot be an empty string") + return result, fmt.Errorf("`containerName` cannot be an empty string") } if strings.ToLower(containerName) != containerName { - return resp, fmt.Errorf("`containerName` must be a lower-cased string") + return result, fmt.Errorf("`containerName` must be a lower-cased string") } if blobName == "" { - return resp, fmt.Errorf("`blobName` cannot be an empty string") + return result, fmt.Errorf("`blobName` cannot be an empty string") } - if (input.StartByte != nil && input.EndByte == nil) || input.StartByte == nil && input.EndByte != nil { - return resp, fmt.Errorf("`input.StartByte` and `input.EndByte` must both be specified, or both be nil") + if (input.StartByte != nil && input.EndByte == nil) || (input.StartByte == nil && input.EndByte != nil) { + return result, fmt.Errorf("`input.StartByte` and `input.EndByte` must both be specified, or both be nil") } opts := client.RequestOptions{ @@ -77,34 +76,37 @@ func (c Client) GetPageRanges(ctx context.Context, containerName, blobName strin return } - resp.HttpResponse, err = req.Execute(ctx) - if err != nil { - err = fmt.Errorf("executing request: %+v", err) - return - } + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response - if resp.HttpResponse != nil { - if resp.HttpResponse.Header != nil { - resp.ContentType = resp.HttpResponse.Header.Get("Content-Type") - resp.ETag = resp.HttpResponse.Header.Get("ETag") + if resp.Header != nil { + result.ContentType = resp.Header.Get("Content-Type") + result.ETag = resp.Header.Get("ETag") - if v := resp.HttpResponse.Header.Get("x-ms-blob-content-length"); v != "" { + if v := resp.Header.Get("x-ms-blob-content-length"); v != "" { i, innerErr := strconv.Atoi(v) if innerErr != nil { - err = fmt.Errorf("Error parsing %q as an integer: %s", v, innerErr) + err = fmt.Errorf("parsing `x-ms-blob-content-length` header value %q: %+v", v, innerErr) return } i64 := int64(i) - resp.ContentLength = &i64 + result.ContentLength = &i64 } } - err = resp.HttpResponse.Unmarshal(&resp) + err = resp.Unmarshal(&result) if err != nil { - return resp, fmt.Errorf("unmarshalling response: %s", err) + err = fmt.Errorf("unmarshalling response: %+v", err) + return } } + if err != nil { + err = fmt.Errorf("executing request: %+v", err) + return + } return } diff --git a/storage/2023-11-03/blob/blobs/incremental_copy_blob.go b/storage/2023-11-03/blob/blobs/incremental_copy_blob.go index d059f11..0423c0f 100644 --- a/storage/2023-11-03/blob/blobs/incremental_copy_blob.go +++ b/storage/2023-11-03/blob/blobs/incremental_copy_blob.go @@ -19,29 +19,32 @@ type IncrementalCopyBlobInput struct { } type IncrementalCopyBlob struct { - HttpResponse *client.Response + HttpResponse *http.Response } // IncrementalCopyBlob copies a snapshot of the source page blob to a destination page blob. // The snapshot is copied such that only the differential changes between the previously copied // snapshot are transferred to the destination. // The copied snapshots are complete copies of the original snapshot and can be read or copied from as usual. -func (c Client) IncrementalCopyBlob(ctx context.Context, containerName, blobName string, input IncrementalCopyBlobInput) (resp IncrementalCopyBlob, err error) { - +func (c Client) IncrementalCopyBlob(ctx context.Context, containerName, blobName string, input IncrementalCopyBlobInput) (result IncrementalCopyBlob, err error) { if containerName == "" { - return resp, fmt.Errorf("`containerName` cannot be an empty string") + err = fmt.Errorf("`containerName` cannot be an empty string") + return } if strings.ToLower(containerName) != containerName { - return resp, fmt.Errorf("`containerName` must be a lower-cased string") + err = fmt.Errorf("`containerName` must be a lower-cased string") + return } if blobName == "" { - return resp, fmt.Errorf("`blobName` cannot be an empty string") + err = fmt.Errorf("`blobName` cannot be an empty string") + return } if input.CopySource == "" { - return resp, fmt.Errorf("`input.CopySource` cannot be an empty string") + err = fmt.Errorf("`input.CopySource` cannot be an empty string") + return } opts := client.RequestOptions{ @@ -61,7 +64,11 @@ func (c Client) IncrementalCopyBlob(ctx context.Context, containerName, blobName return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return diff --git a/storage/2023-11-03/blob/blobs/lease_acquire.go b/storage/2023-11-03/blob/blobs/lease_acquire.go index 214808c..d447756 100644 --- a/storage/2023-11-03/blob/blobs/lease_acquire.go +++ b/storage/2023-11-03/blob/blobs/lease_acquire.go @@ -24,36 +24,41 @@ type AcquireLeaseInput struct { } type AcquireLeaseResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response LeaseID string } // AcquireLease establishes and manages a lock on a blob for write and delete operations. -func (c Client) AcquireLease(ctx context.Context, containerName, blobName string, input AcquireLeaseInput) (resp AcquireLeaseResponse, err error) { - +func (c Client) AcquireLease(ctx context.Context, containerName, blobName string, input AcquireLeaseInput) (result AcquireLeaseResponse, err error) { if containerName == "" { - return resp, fmt.Errorf("`containerName` cannot be an empty string") + err = fmt.Errorf("`containerName` cannot be an empty string") + return } if strings.ToLower(containerName) != containerName { - return resp, fmt.Errorf("`containerName` must be a lower-cased string") + err = fmt.Errorf("`containerName` must be a lower-cased string") + return } if blobName == "" { - return resp, fmt.Errorf("`blobName` cannot be an empty string") + err = fmt.Errorf("`blobName` cannot be an empty string") + return } if input.LeaseID != nil && *input.LeaseID == "" { - return resp, fmt.Errorf("`input.LeaseID` cannot be an empty string, if specified") + err = fmt.Errorf("`input.LeaseID` cannot be an empty string, if specified") + return } if input.ProposedLeaseID != nil && *input.ProposedLeaseID == "" { - return resp, fmt.Errorf("`input.ProposedLeaseID` cannot be an empty string, if specified") + err = fmt.Errorf("`input.ProposedLeaseID` cannot be an empty string, if specified") + return } // An infinite lease duration is -1 seconds. A non-infinite lease can be between 15 and 60 seconds if input.LeaseDuration != -1 && (input.LeaseDuration <= 15 || input.LeaseDuration >= 60) { - return resp, fmt.Errorf("`input.LeaseDuration` must be -1 (infinite), or between 15 and 60 seconds") + err = fmt.Errorf("`input.LeaseDuration` must be -1 (infinite), or between 15 and 60 seconds") + return } opts := client.RequestOptions{ @@ -73,18 +78,20 @@ func (c Client) AcquireLease(ctx context.Context, containerName, blobName string return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + + if resp.Header != nil { + result.LeaseID = resp.Header.Get("x-ms-lease-id") + } + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return } - if resp.HttpResponse != nil { - if resp.HttpResponse.Header != nil { - resp.LeaseID = resp.HttpResponse.Header.Get("x-ms-lease-id") - } - } - return } diff --git a/storage/2023-11-03/blob/blobs/lease_break.go b/storage/2023-11-03/blob/blobs/lease_break.go index 858c306..74e6891 100644 --- a/storage/2023-11-03/blob/blobs/lease_break.go +++ b/storage/2023-11-03/blob/blobs/lease_break.go @@ -26,7 +26,7 @@ type BreakLeaseInput struct { } type BreakLeaseResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response // Approximate time remaining in the lease period, in seconds. // If the break is immediate, 0 is returned. @@ -34,22 +34,25 @@ type BreakLeaseResponse struct { } // BreakLease breaks an existing lock on a blob using the LeaseID. -func (c Client) BreakLease(ctx context.Context, containerName, blobName string, input BreakLeaseInput) (resp BreakLeaseResponse, err error) { - +func (c Client) BreakLease(ctx context.Context, containerName, blobName string, input BreakLeaseInput) (result BreakLeaseResponse, err error) { if containerName == "" { - return resp, fmt.Errorf("`containerName` cannot be an empty string") + err = fmt.Errorf("`containerName` cannot be an empty string") + return } if strings.ToLower(containerName) != containerName { - return resp, fmt.Errorf("`containerName` must be a lower-cased string") + err = fmt.Errorf("`containerName` must be a lower-cased string") + return } if blobName == "" { - return resp, fmt.Errorf("`blobName` cannot be an empty string") + err = fmt.Errorf("`blobName` cannot be an empty string") + return } if input.LeaseID == "" { - return resp, fmt.Errorf("`input.LeaseID` cannot be an empty string") + err = fmt.Errorf("`input.LeaseID` cannot be an empty string") + return } opts := client.RequestOptions{ @@ -69,7 +72,11 @@ func (c Client) BreakLease(ctx context.Context, containerName, blobName string, return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return diff --git a/storage/2023-11-03/blob/blobs/lease_change.go b/storage/2023-11-03/blob/blobs/lease_change.go index c69d054..f983d1d 100644 --- a/storage/2023-11-03/blob/blobs/lease_change.go +++ b/storage/2023-11-03/blob/blobs/lease_change.go @@ -16,32 +16,36 @@ type ChangeLeaseInput struct { } type ChangeLeaseResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response LeaseID string } // ChangeLease changes an existing lock on a blob for another lock. -func (c Client) ChangeLease(ctx context.Context, containerName, blobName string, input ChangeLeaseInput) (resp ChangeLeaseResponse, err error) { - +func (c Client) ChangeLease(ctx context.Context, containerName, blobName string, input ChangeLeaseInput) (result ChangeLeaseResponse, err error) { if containerName == "" { - return resp, fmt.Errorf("`containerName` cannot be an empty string") + err = fmt.Errorf("`containerName` cannot be an empty string") + return } if strings.ToLower(containerName) != containerName { - return resp, fmt.Errorf("`containerName` must be a lower-cased string") + err = fmt.Errorf("`containerName` must be a lower-cased string") + return } if blobName == "" { - return resp, fmt.Errorf("`blobName` cannot be an empty string") + err = fmt.Errorf("`blobName` cannot be an empty string") + return } if input.ExistingLeaseID == "" { - return resp, fmt.Errorf("`input.ExistingLeaseID` cannot be an empty string") + err = fmt.Errorf("`input.ExistingLeaseID` cannot be an empty string") + return } if input.ProposedLeaseID == "" { - return resp, fmt.Errorf("`input.ProposedLeaseID` cannot be an empty string") + err = fmt.Errorf("`input.ProposedLeaseID` cannot be an empty string") + return } opts := client.RequestOptions{ @@ -61,18 +65,20 @@ func (c Client) ChangeLease(ctx context.Context, containerName, blobName string, return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + + if resp.Header != nil { + result.LeaseID = resp.Header.Get("x-ms-lease-id") + } + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return } - if resp.HttpResponse != nil { - if resp.HttpResponse.Header != nil { - resp.LeaseID = resp.HttpResponse.Header.Get("x-ms-lease-id") - } - } - return } diff --git a/storage/2023-11-03/blob/blobs/lease_release.go b/storage/2023-11-03/blob/blobs/lease_release.go index 350493d..2101828 100644 --- a/storage/2023-11-03/blob/blobs/lease_release.go +++ b/storage/2023-11-03/blob/blobs/lease_release.go @@ -11,7 +11,7 @@ import ( ) type ReleaseLeaseResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response } type ReleaseLeaseInput struct { @@ -19,22 +19,25 @@ type ReleaseLeaseInput struct { } // ReleaseLease releases a lock based on the Lease ID. -func (c Client) ReleaseLease(ctx context.Context, containerName, blobName string, input ReleaseLeaseInput) (resp ReleaseLeaseResponse, err error) { - +func (c Client) ReleaseLease(ctx context.Context, containerName, blobName string, input ReleaseLeaseInput) (result ReleaseLeaseResponse, err error) { if containerName == "" { - return resp, fmt.Errorf("`containerName` cannot be an empty string") + err = fmt.Errorf("`containerName` cannot be an empty string") + return } if strings.ToLower(containerName) != containerName { - return resp, fmt.Errorf("`containerName` must be a lower-cased string") + err = fmt.Errorf("`containerName` must be a lower-cased string") + return } if blobName == "" { - return resp, fmt.Errorf("`blobName` cannot be an empty string") + err = fmt.Errorf("`blobName` cannot be an empty string") + return } if input.LeaseID == "" { - return resp, fmt.Errorf("`input.LeaseID` cannot be an empty string") + err = fmt.Errorf("`input.LeaseID` cannot be an empty string") + return } opts := client.RequestOptions{ @@ -54,7 +57,11 @@ func (c Client) ReleaseLease(ctx context.Context, containerName, blobName string return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return diff --git a/storage/2023-11-03/blob/blobs/lease_renew.go b/storage/2023-11-03/blob/blobs/lease_renew.go index 2a82a0a..e43a12d 100644 --- a/storage/2023-11-03/blob/blobs/lease_renew.go +++ b/storage/2023-11-03/blob/blobs/lease_renew.go @@ -11,29 +11,32 @@ import ( ) type RenewLeaseResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response } type RenewLeaseInput struct { LeaseID string } -func (c Client) RenewLease(ctx context.Context, containerName, blobName string, input RenewLeaseInput) (resp RenewLeaseResponse, err error) { - +func (c Client) RenewLease(ctx context.Context, containerName, blobName string, input RenewLeaseInput) (result RenewLeaseResponse, err error) { if containerName == "" { - return resp, fmt.Errorf("`containerName` cannot be an empty string") + err = fmt.Errorf("`containerName` cannot be an empty string") + return } if strings.ToLower(containerName) != containerName { - return resp, fmt.Errorf("`containerName` must be a lower-cased string") + err = fmt.Errorf("`containerName` must be a lower-cased string") + return } if blobName == "" { - return resp, fmt.Errorf("`blobName` cannot be an empty string") + err = fmt.Errorf("`blobName` cannot be an empty string") + return } if input.LeaseID == "" { - return resp, fmt.Errorf("`input.LeaseID` cannot be an empty string") + err = fmt.Errorf("`input.LeaseID` cannot be an empty string") + return } opts := client.RequestOptions{ @@ -53,7 +56,11 @@ func (c Client) RenewLease(ctx context.Context, containerName, blobName string, return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return diff --git a/storage/2023-11-03/blob/blobs/lease_test.go b/storage/2023-11-03/blob/blobs/lease_test.go index 291d471..7ab376d 100644 --- a/storage/2023-11-03/blob/blobs/lease_test.go +++ b/storage/2023-11-03/blob/blobs/lease_test.go @@ -42,7 +42,7 @@ func TestLeaseLifecycle(t *testing.T) { t.Fatalf("building client for environment: %+v", err) } - if err := client.PrepareWithSharedKeyAuth(containersClient.Client, testData, auth.SharedKey); err != nil { + if err = client.PrepareWithSharedKeyAuth(containersClient.Client, testData, auth.SharedKey); err != nil { t.Fatalf("adding authorizer to client: %+v", err) } @@ -57,7 +57,7 @@ func TestLeaseLifecycle(t *testing.T) { t.Fatalf("building client for environment: %+v", err) } - if err := client.PrepareWithSharedKeyAuth(blobClient.Client, testData, auth.SharedKey); err != nil { + if err = client.PrepareWithSharedKeyAuth(blobClient.Client, testData, auth.SharedKey); err != nil { t.Fatalf("adding authorizer to client: %+v", err) } diff --git a/storage/2023-11-03/blob/blobs/lifecycle_test.go b/storage/2023-11-03/blob/blobs/lifecycle_test.go index 4bf927e..71e1093 100644 --- a/storage/2023-11-03/blob/blobs/lifecycle_test.go +++ b/storage/2023-11-03/blob/blobs/lifecycle_test.go @@ -44,7 +44,7 @@ func TestLifecycle(t *testing.T) { t.Fatalf("building client for environment: %+v", err) } - if err := client.PrepareWithSharedKeyAuth(containersClient.Client, testData, auth.SharedKey); err != nil { + if err = client.PrepareWithSharedKeyAuth(containersClient.Client, testData, auth.SharedKey); err != nil { t.Fatalf("adding authorizer to client: %+v", err) } @@ -59,7 +59,7 @@ func TestLifecycle(t *testing.T) { t.Fatalf("building client for environment: %+v", err) } - if err := client.PrepareWithSharedKeyAuth(blobClient.Client, testData, auth.SharedKey); err != nil { + if err = client.PrepareWithSharedKeyAuth(blobClient.Client, testData, auth.SharedKey); err != nil { t.Fatalf("adding authorizer to client: %+v", err) } diff --git a/storage/2023-11-03/blob/blobs/metadata_set.go b/storage/2023-11-03/blob/blobs/metadata_set.go index 604e7a7..ce6c047 100644 --- a/storage/2023-11-03/blob/blobs/metadata_set.go +++ b/storage/2023-11-03/blob/blobs/metadata_set.go @@ -21,26 +21,29 @@ type SetMetaDataInput struct { } type SetMetaDataResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response } // SetMetaData marks the specified blob or snapshot for deletion. The blob is later deleted during garbage collection. -func (c Client) SetMetaData(ctx context.Context, containerName, blobName string, input SetMetaDataInput) (resp SetMetaDataResponse, err error) { - +func (c Client) SetMetaData(ctx context.Context, containerName, blobName string, input SetMetaDataInput) (result SetMetaDataResponse, err error) { if containerName == "" { - return resp, fmt.Errorf("`containerName` cannot be an empty string") + err = fmt.Errorf("`containerName` cannot be an empty string") + return } if strings.ToLower(containerName) != containerName { - return resp, fmt.Errorf("`containerName` must be a lower-cased string") + err = fmt.Errorf("`containerName` must be a lower-cased string") + return } if blobName == "" { - return resp, fmt.Errorf("`blobName` cannot be an empty string") + err = fmt.Errorf("`blobName` cannot be an empty string") + return } - if err := metadata.Validate(input.MetaData); err != nil { - return resp, fmt.Errorf(fmt.Sprintf("`input.MetaData` is not valid: %s.", err)) + if err = metadata.Validate(input.MetaData); err != nil { + err = fmt.Errorf(fmt.Sprintf("`input.MetaData` is not valid: %s.", err)) + return } opts := client.RequestOptions{ @@ -60,7 +63,11 @@ func (c Client) SetMetaData(ctx context.Context, containerName, blobName string, return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return diff --git a/storage/2023-11-03/blob/blobs/properties_get.go b/storage/2023-11-03/blob/blobs/properties_get.go index 86b7c11..1b2c2cd 100644 --- a/storage/2023-11-03/blob/blobs/properties_get.go +++ b/storage/2023-11-03/blob/blobs/properties_get.go @@ -19,7 +19,7 @@ type GetPropertiesInput struct { } type GetPropertiesResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response // The tier of page blob on a premium storage account or tier of block blob on blob storage or general purpose v2 account. AccessTier AccessTier @@ -161,16 +161,18 @@ type GetPropertiesResponse struct { } // GetProperties returns all user-defined metadata, standard HTTP properties, and system properties for the blob -func (c Client) GetProperties(ctx context.Context, containerName, blobName string, input GetPropertiesInput) (resp GetPropertiesResponse, err error) { - +func (c Client) GetProperties(ctx context.Context, containerName, blobName string, input GetPropertiesInput) (result GetPropertiesResponse, err error) { if containerName == "" { - return resp, fmt.Errorf("`containerName` cannot be an empty string") + err = fmt.Errorf("`containerName` cannot be an empty string") + return } if strings.ToLower(containerName) != containerName { - return resp, fmt.Errorf("`containerName` must be a lower-cased string") + err = fmt.Errorf("`containerName` must be a lower-cased string") + return } if blobName == "" { - return resp, fmt.Errorf("`blobName` cannot be an empty string") + err = fmt.Errorf("`blobName` cannot be an empty string") + return } opts := client.RequestOptions{ @@ -190,77 +192,79 @@ func (c Client) GetProperties(ctx context.Context, containerName, blobName strin return } - resp.HttpResponse, err = req.Execute(ctx) - if err != nil { - err = fmt.Errorf("executing request: %+v", err) - return - } - - if resp.HttpResponse != nil { - if resp.HttpResponse.Header != nil { - resp.AccessTier = AccessTier(resp.HttpResponse.Header.Get("x-ms-access-tier")) - resp.AccessTierChangeTime = resp.HttpResponse.Header.Get("x-ms-access-tier-change-time") - resp.ArchiveStatus = ArchiveStatus(resp.HttpResponse.Header.Get("x-ms-archive-status")) - resp.BlobCommittedBlockCount = resp.HttpResponse.Header.Get("x-ms-blob-committed-block-count") - resp.BlobSequenceNumber = resp.HttpResponse.Header.Get("x-ms-blob-sequence-number") - resp.BlobType = BlobType(resp.HttpResponse.Header.Get("x-ms-blob-type")) - resp.CacheControl = resp.HttpResponse.Header.Get("Cache-Control") - resp.ContentDisposition = resp.HttpResponse.Header.Get("Content-Disposition") - resp.ContentEncoding = resp.HttpResponse.Header.Get("Content-Encoding") - resp.ContentLanguage = resp.HttpResponse.Header.Get("Content-Language") - resp.ContentMD5 = resp.HttpResponse.Header.Get("Content-MD5") - resp.ContentType = resp.HttpResponse.Header.Get("Content-Type") - resp.CopyCompletionTime = resp.HttpResponse.Header.Get("x-ms-copy-completion-time") - resp.CopyDestinationSnapshot = resp.HttpResponse.Header.Get("x-ms-copy-destination-snapshot") - resp.CopyID = resp.HttpResponse.Header.Get("x-ms-copy-id") - resp.CopyProgress = resp.HttpResponse.Header.Get("x-ms-copy-progress") - resp.CopySource = resp.HttpResponse.Header.Get("x-ms-copy-source") - resp.CopyStatus = CopyStatus(resp.HttpResponse.Header.Get("x-ms-copy-status")) - resp.CopyStatusDescription = resp.HttpResponse.Header.Get("x-ms-copy-status-description") - resp.CreationTime = resp.HttpResponse.Header.Get("x-ms-creation-time") - resp.ETag = resp.HttpResponse.Header.Get("Etag") - resp.LastModified = resp.HttpResponse.Header.Get("Last-Modified") - resp.LeaseDuration = LeaseDuration(resp.HttpResponse.Header.Get("x-ms-lease-duration")) - resp.LeaseState = LeaseState(resp.HttpResponse.Header.Get("x-ms-lease-state")) - resp.LeaseStatus = LeaseStatus(resp.HttpResponse.Header.Get("x-ms-lease-status")) - resp.MetaData = metadata.ParseFromHeaders(resp.HttpResponse.Header) - - if v := resp.HttpResponse.Header.Get("x-ms-access-tier-inferred"); v != "" { + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + + if resp.Header != nil { + result.AccessTier = AccessTier(resp.Header.Get("x-ms-access-tier")) + result.AccessTierChangeTime = resp.Header.Get("x-ms-access-tier-change-time") + result.ArchiveStatus = ArchiveStatus(resp.Header.Get("x-ms-archive-status")) + result.BlobCommittedBlockCount = resp.Header.Get("x-ms-blob-committed-block-count") + result.BlobSequenceNumber = resp.Header.Get("x-ms-blob-sequence-number") + result.BlobType = BlobType(resp.Header.Get("x-ms-blob-type")) + result.CacheControl = resp.Header.Get("Cache-Control") + result.ContentDisposition = resp.Header.Get("Content-Disposition") + result.ContentEncoding = resp.Header.Get("Content-Encoding") + result.ContentLanguage = resp.Header.Get("Content-Language") + result.ContentMD5 = resp.Header.Get("Content-MD5") + result.ContentType = resp.Header.Get("Content-Type") + result.CopyCompletionTime = resp.Header.Get("x-ms-copy-completion-time") + result.CopyDestinationSnapshot = resp.Header.Get("x-ms-copy-destination-snapshot") + result.CopyID = resp.Header.Get("x-ms-copy-id") + result.CopyProgress = resp.Header.Get("x-ms-copy-progress") + result.CopySource = resp.Header.Get("x-ms-copy-source") + result.CopyStatus = CopyStatus(resp.Header.Get("x-ms-copy-status")) + result.CopyStatusDescription = resp.Header.Get("x-ms-copy-status-description") + result.CreationTime = resp.Header.Get("x-ms-creation-time") + result.ETag = resp.Header.Get("Etag") + result.LastModified = resp.Header.Get("Last-Modified") + result.LeaseDuration = LeaseDuration(resp.Header.Get("x-ms-lease-duration")) + result.LeaseState = LeaseState(resp.Header.Get("x-ms-lease-state")) + result.LeaseStatus = LeaseStatus(resp.Header.Get("x-ms-lease-status")) + result.MetaData = metadata.ParseFromHeaders(resp.Header) + + if v := resp.Header.Get("x-ms-access-tier-inferred"); v != "" { b, innerErr := strconv.ParseBool(v) if innerErr != nil { - err = fmt.Errorf("error parsing %q as a bool: %s", v, innerErr) + err = fmt.Errorf("parsing `x-ms-access-tier-inferred` header value %q: %s", v, innerErr) return } - resp.AccessTierInferred = b + result.AccessTierInferred = b } - if v := resp.HttpResponse.Header.Get("Content-Length"); v != "" { + if v := resp.Header.Get("Content-Length"); v != "" { i, innerErr := strconv.Atoi(v) if innerErr != nil { - err = fmt.Errorf("error parsing %q as an integer: %s", v, innerErr) + err = fmt.Errorf("parsing `Content-Length` header value %q: %s", v, innerErr) } - resp.ContentLength = int64(i) + result.ContentLength = int64(i) } - if v := resp.HttpResponse.Header.Get("x-ms-incremental-copy"); v != "" { + if v := resp.Header.Get("x-ms-incremental-copy"); v != "" { b, innerErr := strconv.ParseBool(v) if innerErr != nil { - err = fmt.Errorf("error parsing %q as a bool: %s", v, innerErr) + err = fmt.Errorf("parsing `x-ms-incremental-copy` header value %q: %s", v, innerErr) return } - resp.IncrementalCopy = b + result.IncrementalCopy = b } - if v := resp.HttpResponse.Header.Get("x-ms-server-encrypted"); v != "" { + if v := resp.Header.Get("x-ms-server-encrypted"); v != "" { b, innerErr := strconv.ParseBool(v) if innerErr != nil { - err = fmt.Errorf("error parsing %q as a bool: %s", v, innerErr) + err = fmt.Errorf("parsing `x-ms-server-encrypted` header value %q: %s", v, innerErr) return } - resp.ServerEncrypted = b + result.ServerEncrypted = b } } } + if err != nil { + err = fmt.Errorf("executing request: %+v", err) + return + } return } diff --git a/storage/2023-11-03/blob/blobs/properties_set.go b/storage/2023-11-03/blob/blobs/properties_set.go index ebe0985..73b417f 100644 --- a/storage/2023-11-03/blob/blobs/properties_set.go +++ b/storage/2023-11-03/blob/blobs/properties_set.go @@ -25,25 +25,24 @@ type SetPropertiesInput struct { } type SetPropertiesResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response BlobSequenceNumber string Etag string } // SetProperties sets system properties on the blob. -func (c Client) SetProperties(ctx context.Context, containerName, blobName string, input SetPropertiesInput) (resp SetPropertiesResponse, err error) { - +func (c Client) SetProperties(ctx context.Context, containerName, blobName string, input SetPropertiesInput) (result SetPropertiesResponse, err error) { if containerName == "" { - return resp, fmt.Errorf("`containerName` cannot be an empty string") + return result, fmt.Errorf("`containerName` cannot be an empty string") } if strings.ToLower(containerName) != containerName { - return resp, fmt.Errorf("`containerName` must be a lower-cased string") + return result, fmt.Errorf("`containerName` must be a lower-cased string") } if blobName == "" { - return resp, fmt.Errorf("`blobName` cannot be an empty string") + return result, fmt.Errorf("`blobName` cannot be an empty string") } opts := client.RequestOptions{ @@ -63,7 +62,11 @@ func (c Client) SetProperties(ctx context.Context, containerName, blobName strin return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return diff --git a/storage/2023-11-03/blob/blobs/put_append_blob.go b/storage/2023-11-03/blob/blobs/put_append_blob.go index 0f3aa30..9217bf4 100644 --- a/storage/2023-11-03/blob/blobs/put_append_blob.go +++ b/storage/2023-11-03/blob/blobs/put_append_blob.go @@ -23,27 +23,30 @@ type PutAppendBlobInput struct { } type PutAppendBlobResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response } // PutAppendBlob is a wrapper around the Put API call (with a stricter input object) // which creates a new append blob, or updates the content of an existing blob. -func (c Client) PutAppendBlob(ctx context.Context, containerName, blobName string, input PutAppendBlobInput) (resp PutAppendBlobResponse, err error) { - +func (c Client) PutAppendBlob(ctx context.Context, containerName, blobName string, input PutAppendBlobInput) (result PutAppendBlobResponse, err error) { if containerName == "" { - return resp, fmt.Errorf("`containerName` cannot be an empty string") + err = fmt.Errorf("`containerName` cannot be an empty string") + return } if strings.ToLower(containerName) != containerName { - return resp, fmt.Errorf("`containerName` must be a lower-cased string") + err = fmt.Errorf("`containerName` must be a lower-cased string") + return } if blobName == "" { - return resp, fmt.Errorf("`blobName` cannot be an empty string") + err = fmt.Errorf("`blobName` cannot be an empty string") + return } - if err := metadata.Validate(input.MetaData); err != nil { - return resp, fmt.Errorf(fmt.Sprintf("`input.MetaData` is not valid: %s.", err)) + if err = metadata.Validate(input.MetaData); err != nil { + err = fmt.Errorf(fmt.Sprintf("`input.MetaData` is not valid: %s.", err)) + return } opts := client.RequestOptions{ @@ -63,7 +66,11 @@ func (c Client) PutAppendBlob(ctx context.Context, containerName, blobName strin return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return diff --git a/storage/2023-11-03/blob/blobs/put_block.go b/storage/2023-11-03/blob/blobs/put_block.go index a6059c4..32b6722 100644 --- a/storage/2023-11-03/blob/blobs/put_block.go +++ b/storage/2023-11-03/blob/blobs/put_block.go @@ -19,32 +19,36 @@ type PutBlockInput struct { } type PutBlockResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response ContentMD5 string } // PutBlock creates a new block to be committed as part of a blob. -func (c Client) PutBlock(ctx context.Context, containerName, blobName string, input PutBlockInput) (resp PutBlockResponse, err error) { - +func (c Client) PutBlock(ctx context.Context, containerName, blobName string, input PutBlockInput) (result PutBlockResponse, err error) { if containerName == "" { - return resp, fmt.Errorf("`containerName` cannot be an empty string") + err = fmt.Errorf("`containerName` cannot be an empty string") + return } if strings.ToLower(containerName) != containerName { - return resp, fmt.Errorf("`containerName` must be a lower-cased string") + err = fmt.Errorf("`containerName` must be a lower-cased string") + return } if blobName == "" { - return resp, fmt.Errorf("`blobName` cannot be an empty string") + err = fmt.Errorf("`blobName` cannot be an empty string") + return } if input.BlockID == "" { - return resp, fmt.Errorf("`input.BlockID` cannot be an empty string") + err = fmt.Errorf("`input.BlockID` cannot be an empty string") + return } if len(input.Content) == 0 { - return resp, fmt.Errorf("`input.Content` cannot be empty") + err = fmt.Errorf("`input.Content` cannot be empty") + return } opts := client.RequestOptions{ @@ -66,10 +70,15 @@ func (c Client) PutBlock(ctx context.Context, containerName, blobName string, in err = req.Marshal(&input.Content) if err != nil { - return resp, fmt.Errorf("marshalling request: %v", err) + err = fmt.Errorf("marshalling request: %+v", err) + return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return diff --git a/storage/2023-11-03/blob/blobs/put_block_blob.go b/storage/2023-11-03/blob/blobs/put_block_blob.go index 462ea17..31ffb25 100644 --- a/storage/2023-11-03/blob/blobs/put_block_blob.go +++ b/storage/2023-11-03/blob/blobs/put_block_blob.go @@ -25,31 +25,35 @@ type PutBlockBlobInput struct { } type PutBlockBlobResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response } // PutBlockBlob is a wrapper around the Put API call (with a stricter input object) // which creates a new block append blob, or updates the content of an existing block blob. -func (c Client) PutBlockBlob(ctx context.Context, containerName, blobName string, input PutBlockBlobInput) (resp PutBlockBlobResponse, err error) { - +func (c Client) PutBlockBlob(ctx context.Context, containerName, blobName string, input PutBlockBlobInput) (result PutBlockBlobResponse, err error) { if containerName == "" { - return resp, fmt.Errorf("`containerName` cannot be an empty string") + err = fmt.Errorf("`containerName` cannot be an empty string") + return } if strings.ToLower(containerName) != containerName { - return resp, fmt.Errorf("`containerName` must be a lower-cased string") + err = fmt.Errorf("`containerName` must be a lower-cased string") + return } if blobName == "" { - return resp, fmt.Errorf("`blobName` cannot be an empty string") + err = fmt.Errorf("`blobName` cannot be an empty string") + return } if input.Content != nil && len(*input.Content) == 0 { - return resp, fmt.Errorf("`input.Content` must either be nil or not empty") + err = fmt.Errorf("`input.Content` must either be nil or not empty") + return } - if err := metadata.Validate(input.MetaData); err != nil { - return resp, fmt.Errorf(fmt.Sprintf("`input.MetaData` is not valid: %s.", err)) + if err = metadata.Validate(input.MetaData); err != nil { + err = fmt.Errorf(fmt.Sprintf("`input.MetaData` is not valid: %s.", err)) + return } opts := client.RequestOptions{ @@ -71,10 +75,15 @@ func (c Client) PutBlockBlob(ctx context.Context, containerName, blobName string err = req.Marshal(&input.Content) if err != nil { - return resp, fmt.Errorf("marshalling request: %v", err) + err = fmt.Errorf("marshalling request: %+v", err) + return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return diff --git a/storage/2023-11-03/blob/blobs/put_block_blob_file.go b/storage/2023-11-03/blob/blobs/put_block_blob_file.go index 932fb32..f5f21b0 100644 --- a/storage/2023-11-03/blob/blobs/put_block_blob_file.go +++ b/storage/2023-11-03/blob/blobs/put_block_blob_file.go @@ -11,7 +11,7 @@ import ( func (c Client) PutBlockBlobFromFile(ctx context.Context, containerName, blobName string, file *os.File, input PutBlockBlobInput) error { fileInfo, err := file.Stat() if err != nil { - return fmt.Errorf("error loading file info: %s", err) + return fmt.Errorf("loading file info: %s", err) } fileSize := fileInfo.Size() @@ -20,14 +20,14 @@ func (c Client) PutBlockBlobFromFile(ctx context.Context, containerName, blobNam _, err = file.ReadAt(bytes, 0) if err != nil { if err != io.EOF { - return fmt.Errorf("Error reading bytes: %s", err) + return fmt.Errorf("reading bytes: %s", err) } } input.Content = &bytes if _, err = c.PutBlockBlob(ctx, containerName, blobName, input); err != nil { - return fmt.Errorf("error putting bytes: %s", err) + return fmt.Errorf("putting bytes: %s", err) } return nil diff --git a/storage/2023-11-03/blob/blobs/put_block_list.go b/storage/2023-11-03/blob/blobs/put_block_list.go index bfe451b..142136d 100644 --- a/storage/2023-11-03/blob/blobs/put_block_list.go +++ b/storage/2023-11-03/blob/blobs/put_block_list.go @@ -34,7 +34,7 @@ type PutBlockListInput struct { } type PutBlockListResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response ContentMD5 string ETag string @@ -44,18 +44,20 @@ type PutBlockListResponse struct { // PutBlockList writes a blob by specifying the list of block IDs that make up the blob. // In order to be written as part of a blob, a block must have been successfully written // to the server in a prior Put Block operation. -func (c Client) PutBlockList(ctx context.Context, containerName, blobName string, input PutBlockListInput) (resp PutBlockListResponse, err error) { - +func (c Client) PutBlockList(ctx context.Context, containerName, blobName string, input PutBlockListInput) (result PutBlockListResponse, err error) { if containerName == "" { - return resp, fmt.Errorf("`containerName` cannot be an empty string") + err = fmt.Errorf("`containerName` cannot be an empty string") + return } if strings.ToLower(containerName) != containerName { - return resp, fmt.Errorf("`containerName` must be a lower-cased string") + err = fmt.Errorf("`containerName` must be a lower-cased string") + return } if blobName == "" { - return resp, fmt.Errorf("`blobName` cannot be an empty string") + err = fmt.Errorf("`blobName` cannot be an empty string") + return } opts := client.RequestOptions{ @@ -77,23 +79,26 @@ func (c Client) PutBlockList(ctx context.Context, containerName, blobName string err = req.Marshal(&input.BlockList) if err != nil { - return resp, fmt.Errorf("marshalling request: %v", err) + err = fmt.Errorf("marshalling request: %+v", err) + return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + + if resp.Header != nil { + result.ContentMD5 = resp.Header.Get("Content-MD5") + result.ETag = resp.Header.Get("ETag") + result.LastModified = resp.Header.Get("Last-Modified") + } + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return } - if resp.HttpResponse != nil { - if resp.HttpResponse.Header != nil { - resp.ContentMD5 = resp.HttpResponse.Header.Get("Content-MD5") - resp.ETag = resp.HttpResponse.Header.Get("ETag") - resp.LastModified = resp.HttpResponse.Header.Get("Last-Modified") - } - } - return } diff --git a/storage/2023-11-03/blob/blobs/put_block_url.go b/storage/2023-11-03/blob/blobs/put_block_url.go index cd8487c..3cac427 100644 --- a/storage/2023-11-03/blob/blobs/put_block_url.go +++ b/storage/2023-11-03/blob/blobs/put_block_url.go @@ -20,31 +20,35 @@ type PutBlockFromURLInput struct { } type PutBlockFromURLResponse struct { - HttpResponse *client.Response ContentMD5 string + HttpResponse *http.Response } // PutBlockFromURL creates a new block to be committed as part of a blob where the contents are read from a URL -func (c Client) PutBlockFromURL(ctx context.Context, containerName, blobName string, input PutBlockFromURLInput) (resp PutBlockFromURLResponse, err error) { - +func (c Client) PutBlockFromURL(ctx context.Context, containerName, blobName string, input PutBlockFromURLInput) (result PutBlockFromURLResponse, err error) { if containerName == "" { - return resp, fmt.Errorf("`containerName` cannot be an empty string") + err = fmt.Errorf("`containerName` cannot be an empty string") + return } if strings.ToLower(containerName) != containerName { - return resp, fmt.Errorf("`containerName` must be a lower-cased string") + err = fmt.Errorf("`containerName` must be a lower-cased string") + return } if blobName == "" { - return resp, fmt.Errorf("`blobName` cannot be an empty string") + err = fmt.Errorf("`blobName` cannot be an empty string") + return } if input.BlockID == "" { - return resp, fmt.Errorf("`input.BlockID` cannot be an empty string") + err = fmt.Errorf("`input.BlockID` cannot be an empty string") + return } if input.CopySource == "" { - return resp, fmt.Errorf("`input.CopySource` cannot be an empty string") + err = fmt.Errorf("`input.CopySource` cannot be an empty string") + return } opts := client.RequestOptions{ @@ -64,18 +68,20 @@ func (c Client) PutBlockFromURL(ctx context.Context, containerName, blobName str return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + + if resp.Header != nil { + result.ContentMD5 = resp.Header.Get("Content-MD5") + } + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return } - if resp.HttpResponse != nil { - if resp.HttpResponse.Header != nil { - resp.ContentMD5 = resp.HttpResponse.Header.Get("Content-MD5") - } - } - return } diff --git a/storage/2023-11-03/blob/blobs/put_page_blob.go b/storage/2023-11-03/blob/blobs/put_page_blob.go index 2b733c4..281d20e 100644 --- a/storage/2023-11-03/blob/blobs/put_page_blob.go +++ b/storage/2023-11-03/blob/blobs/put_page_blob.go @@ -28,27 +28,30 @@ type PutPageBlobInput struct { } type PutPageBlobResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response } // PutPageBlob is a wrapper around the Put API call (with a stricter input object) // which creates a new block blob, or updates the content of an existing page blob. -func (c Client) PutPageBlob(ctx context.Context, containerName, blobName string, input PutPageBlobInput) (resp PutPageBlobResponse, err error) { - +func (c Client) PutPageBlob(ctx context.Context, containerName, blobName string, input PutPageBlobInput) (result PutPageBlobResponse, err error) { if containerName == "" { - return resp, fmt.Errorf("`containerName` cannot be an empty string") + err = fmt.Errorf("`containerName` cannot be an empty string") + return } if strings.ToLower(containerName) != containerName { - return resp, fmt.Errorf("`containerName` must be a lower-cased string") + err = fmt.Errorf("`containerName` must be a lower-cased string") + return } if blobName == "" { - return resp, fmt.Errorf("`blobName` cannot be an empty string") + err = fmt.Errorf("`blobName` cannot be an empty string") + return } if input.BlobContentLengthBytes == 0 || input.BlobContentLengthBytes%512 != 0 { - return resp, fmt.Errorf("`input.BlobContentLengthBytes` must be aligned to a 512-byte boundary") + err = fmt.Errorf("`input.BlobContentLengthBytes` must be aligned to a 512-byte boundary") + return } opts := client.RequestOptions{ @@ -68,7 +71,11 @@ func (c Client) PutPageBlob(ctx context.Context, containerName, blobName string, return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return diff --git a/storage/2023-11-03/blob/blobs/put_page_clear.go b/storage/2023-11-03/blob/blobs/put_page_clear.go index 1a99513..9b8ad4f 100644 --- a/storage/2023-11-03/blob/blobs/put_page_clear.go +++ b/storage/2023-11-03/blob/blobs/put_page_clear.go @@ -18,30 +18,34 @@ type PutPageClearInput struct { } type PutPageClearResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response } // PutPageClear clears a range of pages within a page blob. -func (c Client) PutPageClear(ctx context.Context, containerName, blobName string, input PutPageClearInput) (resp PutPageClearResponse, err error) { - +func (c Client) PutPageClear(ctx context.Context, containerName, blobName string, input PutPageClearInput) (result PutPageClearResponse, err error) { if containerName == "" { - return resp, fmt.Errorf("`containerName` cannot be an empty string") + err = fmt.Errorf("`containerName` cannot be an empty string") + return } if strings.ToLower(containerName) != containerName { - return resp, fmt.Errorf("`containerName` must be a lower-cased string") + err = fmt.Errorf("`containerName` must be a lower-cased string") + return } if blobName == "" { - return resp, fmt.Errorf("`blobName` cannot be an empty string") + err = fmt.Errorf("`blobName` cannot be an empty string") + return } if input.StartByte < 0 { - return resp, fmt.Errorf("`input.StartByte` must be greater than or equal to 0") + err = fmt.Errorf("`input.StartByte` must be greater than or equal to 0") + return } if input.EndByte <= 0 { - return resp, fmt.Errorf("`input.EndByte` must be greater than 0") + err = fmt.Errorf("`input.EndByte` must be greater than 0") + return } opts := client.RequestOptions{ @@ -61,7 +65,11 @@ func (c Client) PutPageClear(ctx context.Context, containerName, blobName string return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return diff --git a/storage/2023-11-03/blob/blobs/put_page_update.go b/storage/2023-11-03/blob/blobs/put_page_update.go index 448fe34..4019cc3 100644 --- a/storage/2023-11-03/blob/blobs/put_page_update.go +++ b/storage/2023-11-03/blob/blobs/put_page_update.go @@ -29,7 +29,7 @@ type PutPageUpdateInput struct { } type PutPageUpdateResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response BlobSequenceNumber string ContentMD5 string @@ -37,32 +37,37 @@ type PutPageUpdateResponse struct { } // PutPageUpdate writes a range of pages to a page blob. -func (c Client) PutPageUpdate(ctx context.Context, containerName, blobName string, input PutPageUpdateInput) (resp PutPageUpdateResponse, err error) { - +func (c Client) PutPageUpdate(ctx context.Context, containerName, blobName string, input PutPageUpdateInput) (result PutPageUpdateResponse, err error) { if containerName == "" { - return resp, fmt.Errorf("`containerName` cannot be an empty string") + err = fmt.Errorf("`containerName` cannot be an empty string") + return } if strings.ToLower(containerName) != containerName { - return resp, fmt.Errorf("`containerName` must be a lower-cased string") + err = fmt.Errorf("`containerName` must be a lower-cased string") + return } if blobName == "" { - return resp, fmt.Errorf("`blobName` cannot be an empty string") + err = fmt.Errorf("`blobName` cannot be an empty string") + return } if input.StartByte < 0 { - return resp, fmt.Errorf("`input.StartByte` must be greater than or equal to 0") + err = fmt.Errorf("`input.StartByte` must be greater than or equal to 0") + return } if input.EndByte <= 0 { - return resp, fmt.Errorf("`input.EndByte` must be greater than 0") + err = fmt.Errorf("`input.EndByte` must be greater than 0") + return } expectedSize := (input.EndByte - input.StartByte) + 1 actualSize := int64(len(input.Content)) if expectedSize != actualSize { - return resp, fmt.Errorf(fmt.Sprintf("Content Size was defined as %d but got %d.", expectedSize, actualSize)) + err = fmt.Errorf(fmt.Sprintf("Content Size was defined as %d but got %d.", expectedSize, actualSize)) + return } opts := client.RequestOptions{ @@ -82,21 +87,26 @@ func (c Client) PutPageUpdate(ctx context.Context, containerName, blobName strin return } + // this is needed to avoid `Content-Length: 0` in the request req.Body = io.NopCloser(bytes.NewReader(input.Content)) req.ContentLength = int64(len(input.Content)) - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + + if resp.Header != nil { + result.BlobSequenceNumber = resp.Header.Get("x-ms-blob-sequence-number") + result.ContentMD5 = resp.Header.Get("Content-MD5") + result.LastModified = resp.Header.Get("Last-Modified") + } + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return } - if resp.HttpResponse != nil && resp.HttpResponse.Header != nil { - resp.BlobSequenceNumber = resp.HttpResponse.Header.Get("x-ms-blob-sequence-number") - resp.ContentMD5 = resp.HttpResponse.Header.Get("Content-MD5") - resp.LastModified = resp.HttpResponse.Header.Get("Last-Modified") - } - return } diff --git a/storage/2023-11-03/blob/blobs/set_tier.go b/storage/2023-11-03/blob/blobs/set_tier.go index 35cca5b..66b9d64 100644 --- a/storage/2023-11-03/blob/blobs/set_tier.go +++ b/storage/2023-11-03/blob/blobs/set_tier.go @@ -15,22 +15,24 @@ type SetTierInput struct { } type SetTierResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response } // SetTier sets the tier on a blob. -func (c Client) SetTier(ctx context.Context, containerName, blobName string, input SetTierInput) (resp SetTierResponse, err error) { - +func (c Client) SetTier(ctx context.Context, containerName, blobName string, input SetTierInput) (result SetTierResponse, err error) { if containerName == "" { - return resp, fmt.Errorf("`containerName` cannot be an empty string") + err = fmt.Errorf("`containerName` cannot be an empty string") + return } if strings.ToLower(containerName) != containerName { - return resp, fmt.Errorf("`containerName` must be a lower-cased string") + err = fmt.Errorf("`containerName` must be a lower-cased string") + return } if blobName == "" { - return resp, fmt.Errorf("`blobName` cannot be an empty string") + err = fmt.Errorf("`blobName` cannot be an empty string") + return } opts := client.RequestOptions{ @@ -51,7 +53,11 @@ func (c Client) SetTier(ctx context.Context, containerName, blobName string, inp return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return diff --git a/storage/2023-11-03/blob/blobs/snapshot.go b/storage/2023-11-03/blob/blobs/snapshot.go index 8a90dcd..0a8f8ca 100644 --- a/storage/2023-11-03/blob/blobs/snapshot.go +++ b/storage/2023-11-03/blob/blobs/snapshot.go @@ -41,7 +41,7 @@ type SnapshotInput struct { } type SnapshotResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response // The ETag of the snapshot ETag string @@ -53,22 +53,25 @@ type SnapshotResponse struct { } // Snapshot captures a Snapshot of a given Blob -func (c Client) Snapshot(ctx context.Context, containerName, blobName string, input SnapshotInput) (resp SnapshotResponse, err error) { - +func (c Client) Snapshot(ctx context.Context, containerName, blobName string, input SnapshotInput) (result SnapshotResponse, err error) { if containerName == "" { - return resp, fmt.Errorf("`containerName` cannot be an empty string") + err = fmt.Errorf("`containerName` cannot be an empty string") + return } if strings.ToLower(containerName) != containerName { - return resp, fmt.Errorf("`containerName` must be a lower-cased string") + err = fmt.Errorf("`containerName` must be a lower-cased string") + return } if blobName == "" { - return resp, fmt.Errorf("`blobName` cannot be an empty string") + err = fmt.Errorf("`blobName` cannot be an empty string") + return } - if err := metadata.Validate(input.MetaData); err != nil { - return resp, fmt.Errorf(fmt.Sprintf("`input.MetaData` is not valid: %s.", err)) + if err = metadata.Validate(input.MetaData); err != nil { + err = fmt.Errorf(fmt.Sprintf("`input.MetaData` is not valid: %s.", err)) + return } opts := client.RequestOptions{ @@ -88,17 +91,21 @@ func (c Client) Snapshot(ctx context.Context, containerName, blobName string, in return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + + if resp.Header != nil { + result.ETag = resp.Header.Get("ETag") + result.SnapshotDateTime = resp.Header.Get("x-ms-snapshot") + } + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return } - if resp.HttpResponse != nil && resp.HttpResponse.Header != nil { - resp.ETag = resp.HttpResponse.Header.Get("ETag") - resp.SnapshotDateTime = resp.HttpResponse.Header.Get("x-ms-snapshot") - } - return } diff --git a/storage/2023-11-03/blob/blobs/snapshot_get_properties.go b/storage/2023-11-03/blob/blobs/snapshot_get_properties.go index 57a02f3..09e53cf 100644 --- a/storage/2023-11-03/blob/blobs/snapshot_get_properties.go +++ b/storage/2023-11-03/blob/blobs/snapshot_get_properties.go @@ -23,22 +23,25 @@ type GetSnapshotPropertiesInput struct { // GetSnapshotProperties returns all user-defined metadata, standard HTTP properties, and system properties for // the specified snapshot of a blob -func (c Client) GetSnapshotProperties(ctx context.Context, containerName, blobName string, input GetSnapshotPropertiesInput) (resp GetPropertiesResponse, err error) { - +func (c Client) GetSnapshotProperties(ctx context.Context, containerName, blobName string, input GetSnapshotPropertiesInput) (result GetPropertiesResponse, err error) { if containerName == "" { - return resp, fmt.Errorf("`containerName` cannot be an empty string") + err = fmt.Errorf("`containerName` cannot be an empty string") + return } if strings.ToLower(containerName) != containerName { - return resp, fmt.Errorf("`containerName` must be a lower-cased string") + err = fmt.Errorf("`containerName` must be a lower-cased string") + return } if blobName == "" { - return resp, fmt.Errorf("`blobName` cannot be an empty string") + err = fmt.Errorf("`blobName` cannot be an empty string") + return } if input.SnapshotID == "" { - return resp, fmt.Errorf("`input.SnapshotID` cannot be an empty string") + err = fmt.Errorf("`input.SnapshotID` cannot be an empty string") + return } opts := client.RequestOptions{ @@ -58,81 +61,86 @@ func (c Client) GetSnapshotProperties(ctx context.Context, containerName, blobNa return } - resp.HttpResponse, err = req.Execute(ctx) - if err != nil { - err = fmt.Errorf("executing request: %+v", err) - return - } - - if resp.HttpResponse != nil { - if resp.HttpResponse.Header != nil { - resp.AccessTier = AccessTier(resp.HttpResponse.Header.Get("x-ms-access-tier")) - resp.AccessTierChangeTime = resp.HttpResponse.Header.Get("x-ms-access-tier-change-time") - resp.ArchiveStatus = ArchiveStatus(resp.HttpResponse.Header.Get("x-ms-archive-status")) - resp.BlobCommittedBlockCount = resp.HttpResponse.Header.Get("x-ms-blob-committed-block-count") - resp.BlobSequenceNumber = resp.HttpResponse.Header.Get("x-ms-blob-sequence-number") - resp.BlobType = BlobType(resp.HttpResponse.Header.Get("x-ms-blob-type")) - resp.CacheControl = resp.HttpResponse.Header.Get("Cache-Control") - resp.ContentDisposition = resp.HttpResponse.Header.Get("Content-Disposition") - resp.ContentEncoding = resp.HttpResponse.Header.Get("Content-Encoding") - resp.ContentLanguage = resp.HttpResponse.Header.Get("Content-Language") - resp.ContentMD5 = resp.HttpResponse.Header.Get("Content-MD5") - resp.ContentType = resp.HttpResponse.Header.Get("Content-Type") - resp.CopyCompletionTime = resp.HttpResponse.Header.Get("x-ms-copy-completion-time") - resp.CopyDestinationSnapshot = resp.HttpResponse.Header.Get("x-ms-copy-destination-snapshot") - resp.CopyID = resp.HttpResponse.Header.Get("x-ms-copy-id") - resp.CopyProgress = resp.HttpResponse.Header.Get("x-ms-copy-progress") - resp.CopySource = resp.HttpResponse.Header.Get("x-ms-copy-source") - resp.CopyStatus = CopyStatus(resp.HttpResponse.Header.Get("x-ms-copy-status")) - resp.CopyStatusDescription = resp.HttpResponse.Header.Get("x-ms-copy-status-description") - resp.CreationTime = resp.HttpResponse.Header.Get("x-ms-creation-time") - resp.ETag = resp.HttpResponse.Header.Get("Etag") - resp.LastModified = resp.HttpResponse.Header.Get("Last-Modified") - resp.LeaseDuration = LeaseDuration(resp.HttpResponse.Header.Get("x-ms-lease-duration")) - resp.LeaseState = LeaseState(resp.HttpResponse.Header.Get("x-ms-lease-state")) - resp.LeaseStatus = LeaseStatus(resp.HttpResponse.Header.Get("x-ms-lease-status")) - resp.MetaData = metadata.ParseFromHeaders(resp.HttpResponse.Header) - - if v := resp.HttpResponse.Header.Get("x-ms-access-tier-inferred"); v != "" { - b, innerErr := strconv.ParseBool(v) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + + if resp.Header != nil { + result.AccessTier = AccessTier(resp.Header.Get("x-ms-access-tier")) + result.AccessTierChangeTime = resp.Header.Get("x-ms-access-tier-change-time") + result.ArchiveStatus = ArchiveStatus(resp.Header.Get("x-ms-archive-status")) + result.BlobCommittedBlockCount = resp.Header.Get("x-ms-blob-committed-block-count") + result.BlobSequenceNumber = resp.Header.Get("x-ms-blob-sequence-number") + result.BlobType = BlobType(resp.Header.Get("x-ms-blob-type")) + result.CacheControl = resp.Header.Get("Cache-Control") + result.ContentDisposition = resp.Header.Get("Content-Disposition") + result.ContentEncoding = resp.Header.Get("Content-Encoding") + result.ContentLanguage = resp.Header.Get("Content-Language") + result.ContentMD5 = resp.Header.Get("Content-MD5") + result.ContentType = resp.Header.Get("Content-Type") + result.CopyCompletionTime = resp.Header.Get("x-ms-copy-completion-time") + result.CopyDestinationSnapshot = resp.Header.Get("x-ms-copy-destination-snapshot") + result.CopyID = resp.Header.Get("x-ms-copy-id") + result.CopyProgress = resp.Header.Get("x-ms-copy-progress") + result.CopySource = resp.Header.Get("x-ms-copy-source") + result.CopyStatus = CopyStatus(resp.Header.Get("x-ms-copy-status")) + result.CopyStatusDescription = resp.Header.Get("x-ms-copy-status-description") + result.CreationTime = resp.Header.Get("x-ms-creation-time") + result.ETag = resp.Header.Get("Etag") + result.LastModified = resp.Header.Get("Last-Modified") + result.LeaseDuration = LeaseDuration(resp.Header.Get("x-ms-lease-duration")) + result.LeaseState = LeaseState(resp.Header.Get("x-ms-lease-state")) + result.LeaseStatus = LeaseStatus(resp.Header.Get("x-ms-lease-status")) + result.MetaData = metadata.ParseFromHeaders(resp.Header) + + if v := resp.Header.Get("Content-Length"); v != "" { + i, innerErr := strconv.Atoi(v) if innerErr != nil { - err = fmt.Errorf("error parsing %q as a bool: %s", v, innerErr) - return + err = fmt.Errorf("parsing `Content-Length` header value %q: %+v", v, innerErr) } - resp.AccessTierInferred = b + result.ContentLength = int64(i) } - if v := resp.HttpResponse.Header.Get("Content-Length"); v != "" { - i, innerErr := strconv.Atoi(v) + if v := resp.Header.Get("x-ms-access-tier-inferred"); v != "" { + b, innerErr := strconv.ParseBool(v) if innerErr != nil { - err = fmt.Errorf("error parsing %q as an integer: %s", v, innerErr) + err = fmt.Errorf("parsing `x-ms-access-tier-inferred` header value %q: %+v", v, innerErr) + return } - resp.ContentLength = int64(i) + result.AccessTierInferred = b } - if v := resp.HttpResponse.Header.Get("x-ms-incremental-copy"); v != "" { + if v := resp.Header.Get("x-ms-incremental-copy"); v != "" { b, innerErr := strconv.ParseBool(v) if innerErr != nil { - err = fmt.Errorf("error parsing %q as a bool: %s", v, innerErr) + err = fmt.Errorf("parsing `x-ms-incremental-copy` header value %q: %+v", v, innerErr) return } - resp.IncrementalCopy = b + result.IncrementalCopy = b } - if v := resp.HttpResponse.Header.Get("x-ms-server-encrypted"); v != "" { + if v := resp.Header.Get("x-ms-server-encrypted"); v != "" { b, innerErr := strconv.ParseBool(v) if innerErr != nil { - err = fmt.Errorf("error parsing %q as a bool: %s", v, innerErr) + err = fmt.Errorf("parsing `\"x-ms-server-encrypted` header value %q: %+v", v, innerErr) return } - resp.ServerEncrypted = b + result.ServerEncrypted = b } } } + if err != nil { + err = fmt.Errorf("executing request: %+v", err) + return + } + + if result.HttpResponse != nil { + } return } diff --git a/storage/2023-11-03/blob/blobs/undelete.go b/storage/2023-11-03/blob/blobs/undelete.go index e46277c..149971f 100644 --- a/storage/2023-11-03/blob/blobs/undelete.go +++ b/storage/2023-11-03/blob/blobs/undelete.go @@ -11,22 +11,24 @@ import ( ) type UndeleteResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response } // Undelete restores the contents and metadata of soft deleted blob and any associated soft deleted snapshots. -func (c Client) Undelete(ctx context.Context, containerName, blobName string) (resp UndeleteResponse, err error) { - +func (c Client) Undelete(ctx context.Context, containerName, blobName string) (result UndeleteResponse, err error) { if containerName == "" { - return resp, fmt.Errorf("`containerName` cannot be an empty string") + err = fmt.Errorf("`containerName` cannot be an empty string") + return } if strings.ToLower(containerName) != containerName { - return resp, fmt.Errorf("`containerName` must be a lower-cased string") + err = fmt.Errorf("`containerName` must be a lower-cased string") + return } if blobName == "" { - return resp, fmt.Errorf("`blobName` cannot be an empty string") + err = fmt.Errorf("`blobName` cannot be an empty string") + return } opts := client.RequestOptions{ @@ -44,7 +46,11 @@ func (c Client) Undelete(ctx context.Context, containerName, blobName string) (r return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return diff --git a/storage/2023-11-03/blob/containers/create.go b/storage/2023-11-03/blob/containers/create.go index 1acbae8..02bbce7 100644 --- a/storage/2023-11-03/blob/containers/create.go +++ b/storage/2023-11-03/blob/containers/create.go @@ -19,18 +19,20 @@ type CreateInput struct { } type CreateResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response Error *ErrorResponse `xml:"Error"` } // Create creates a new container under the specified account. // If the container with the same name already exists, the operation fails. -func (c Client) Create(ctx context.Context, containerName string, input CreateInput) (resp CreateResponse, err error) { +func (c Client) Create(ctx context.Context, containerName string, input CreateInput) (result CreateResponse, err error) { if containerName == "" { - return resp, fmt.Errorf("`containerName` cannot be an empty string") + err = fmt.Errorf("`containerName` cannot be an empty string") + return } - if err := metadata.Validate(input.MetaData); err != nil { - return resp, fmt.Errorf("`input.MetaData` is not valid: %+v", err) + if err = metadata.Validate(input.MetaData); err != nil { + err = fmt.Errorf("`input.MetaData` is not valid: %+v", err) + return } opts := client.RequestOptions{ @@ -45,12 +47,18 @@ func (c Client) Create(ctx context.Context, containerName string, input CreateIn }, Path: fmt.Sprintf("/%s", containerName), } + req, err := c.Client.NewRequest(ctx, opts) if err != nil { err = fmt.Errorf("building request: %+v", err) return } - resp.HttpResponse, err = req.Execute(ctx) + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return diff --git a/storage/2023-11-03/blob/containers/delete.go b/storage/2023-11-03/blob/containers/delete.go index 0aea0ed..d654e4a 100644 --- a/storage/2023-11-03/blob/containers/delete.go +++ b/storage/2023-11-03/blob/containers/delete.go @@ -9,14 +9,15 @@ import ( ) type DeleteResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response } // Delete marks the specified container for deletion. // The container and any blobs contained within it are later deleted during garbage collection. -func (c Client) Delete(ctx context.Context, containerName string) (resp DeleteResponse, err error) { +func (c Client) Delete(ctx context.Context, containerName string) (result DeleteResponse, err error) { if containerName == "" { - return resp, fmt.Errorf("`containerName` cannot be an empty string") + err = fmt.Errorf("`containerName` cannot be an empty string") + return } opts := client.RequestOptions{ @@ -28,12 +29,18 @@ func (c Client) Delete(ctx context.Context, containerName string) (resp DeleteRe OptionsObject: containerOptions{}, Path: fmt.Sprintf("/%s", containerName), } + req, err := c.Client.NewRequest(ctx, opts) if err != nil { err = fmt.Errorf("building request: %+v", err) return } - resp.HttpResponse, err = req.Execute(ctx) + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return diff --git a/storage/2023-11-03/blob/containers/get_properties.go b/storage/2023-11-03/blob/containers/get_properties.go index 2655b0b..44bf7a1 100644 --- a/storage/2023-11-03/blob/containers/get_properties.go +++ b/storage/2023-11-03/blob/containers/get_properties.go @@ -16,14 +16,15 @@ type GetPropertiesInput struct { } type GetPropertiesResponse struct { - HttpResponse *client.Response - Model *ContainerProperties + ContainerProperties + HttpResponse *http.Response } // GetProperties returns the properties for this Container without a Lease -func (c Client) GetProperties(ctx context.Context, containerName string, input GetPropertiesInput) (resp GetPropertiesResponse, err error) { +func (c Client) GetProperties(ctx context.Context, containerName string, input GetPropertiesInput) (result GetPropertiesResponse, err error) { if containerName == "" { - return resp, fmt.Errorf("`containerName` cannot be an empty string") + err = fmt.Errorf("`containerName` cannot be an empty string") + return } opts := client.RequestOptions{ @@ -37,40 +38,45 @@ func (c Client) GetProperties(ctx context.Context, containerName string, input G }, Path: fmt.Sprintf("/%s", containerName), } + req, err := c.Client.NewRequest(ctx, opts) if err != nil { err = fmt.Errorf("building request: %+v", err) return } - resp.HttpResponse, err = req.Execute(ctx) + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + + if resp.Header != nil { + result.LeaseStatus = LeaseStatus(resp.Header.Get("x-ms-lease-status")) + result.LeaseState = LeaseState(resp.Header.Get("x-ms-lease-state")) + if result.LeaseStatus == Locked { + duration := LeaseDuration(resp.Header.Get("x-ms-lease-duration")) + result.LeaseDuration = &duration + } + + // If this header is not returned in the response, the container is private to the account owner. + accessLevel := resp.Header.Get("x-ms-blob-public-access") + if accessLevel != "" { + result.AccessLevel = AccessLevel(accessLevel) + } else { + result.AccessLevel = Private + } + + // we can't necessarily use strconv.ParseBool here since this could be nil (only in some API versions) + result.HasImmutabilityPolicy = strings.EqualFold(resp.Header.Get("x-ms-has-immutability-policy"), "true") + result.HasLegalHold = strings.EqualFold(resp.Header.Get("x-ms-has-legal-hold"), "true") + result.MetaData = metadata.ParseFromHeaders(resp.Header) + } + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return } - if resp.HttpResponse != nil { - resp.Model = &ContainerProperties{} - resp.Model.LeaseStatus = LeaseStatus(resp.HttpResponse.Header.Get("x-ms-lease-status")) - resp.Model.LeaseState = LeaseState(resp.HttpResponse.Header.Get("x-ms-lease-state")) - if resp.Model.LeaseStatus == Locked { - duration := LeaseDuration(resp.HttpResponse.Header.Get("x-ms-lease-duration")) - resp.Model.LeaseDuration = &duration - } - - // If this header is not returned in the response, the container is private to the account owner. - accessLevel := resp.HttpResponse.Header.Get("x-ms-blob-public-access") - if accessLevel != "" { - resp.Model.AccessLevel = AccessLevel(accessLevel) - } else { - resp.Model.AccessLevel = Private - } - - // we can't necessarily use strconv.ParseBool here since this could be nil (only in some API versions) - resp.Model.HasImmutabilityPolicy = strings.EqualFold(resp.HttpResponse.Header.Get("x-ms-has-immutability-policy"), "true") - resp.Model.HasLegalHold = strings.EqualFold(resp.HttpResponse.Header.Get("x-ms-has-legal-hold"), "true") - resp.Model.MetaData = metadata.ParseFromHeaders(resp.HttpResponse.Header) - } - return } diff --git a/storage/2023-11-03/blob/containers/lease_acquire.go b/storage/2023-11-03/blob/containers/lease_acquire.go index 409f15a..a863c14 100644 --- a/storage/2023-11-03/blob/containers/lease_acquire.go +++ b/storage/2023-11-03/blob/containers/lease_acquire.go @@ -18,8 +18,8 @@ type AcquireLeaseInput struct { } type AcquireLeaseResponse struct { - HttpResponse *client.Response - Model *AcquireLeaseModel + AcquireLeaseModel + HttpResponse *http.Response } type AcquireLeaseModel struct { @@ -27,13 +27,13 @@ type AcquireLeaseModel struct { } // AcquireLease establishes and manages a lock on a container for delete operations. -func (c Client) AcquireLease(ctx context.Context, containerName string, input AcquireLeaseInput) (resp AcquireLeaseResponse, err error) { +func (c Client) AcquireLease(ctx context.Context, containerName string, input AcquireLeaseInput) (result AcquireLeaseResponse, err error) { if containerName == "" { - return resp, fmt.Errorf("`containerName` cannot be an empty string") + return result, fmt.Errorf("`containerName` cannot be an empty string") } // An infinite lease duration is -1 seconds. A non-infinite lease can be between 15 and 60 seconds if input.LeaseDuration != -1 && (input.LeaseDuration <= 15 || input.LeaseDuration >= 60) { - return resp, fmt.Errorf("`input.LeaseDuration` must be -1 (infinite), or between 15 and 60 seconds") + return result, fmt.Errorf("`input.LeaseDuration` must be -1 (infinite), or between 15 and 60 seconds") } opts := client.RequestOptions{ @@ -48,23 +48,27 @@ func (c Client) AcquireLease(ctx context.Context, containerName string, input Ac }, Path: fmt.Sprintf("/%s", containerName), } + req, err := c.Client.NewRequest(ctx, opts) if err != nil { err = fmt.Errorf("building request: %+v", err) return } - resp.HttpResponse, err = req.Execute(ctx) + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + + if resp.Header != nil { + result.LeaseID = resp.Header.Get("x-ms-lease-id") + } + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return } - if resp.HttpResponse != nil { - resp.Model = &AcquireLeaseModel{ - LeaseID: resp.HttpResponse.Header.Get("x-ms-lease-id"), - } - } - return } diff --git a/storage/2023-11-03/blob/containers/lease_break.go b/storage/2023-11-03/blob/containers/lease_break.go index 0ede9a8..b141e25 100644 --- a/storage/2023-11-03/blob/containers/lease_break.go +++ b/storage/2023-11-03/blob/containers/lease_break.go @@ -3,11 +3,10 @@ package containers import ( "context" "fmt" - "net/http" - "strconv" - "github.com/hashicorp/go-azure-sdk/sdk/client" "github.com/hashicorp/go-azure-sdk/sdk/odata" + "net/http" + "strconv" ) type BreakLeaseInput struct { @@ -25,8 +24,8 @@ type BreakLeaseInput struct { } type BreakLeaseResponse struct { - HttpResponse *client.Response - Model *BreakLeaseModel + BreakLeaseModel + HttpResponse *http.Response } type BreakLeaseModel struct { @@ -36,12 +35,12 @@ type BreakLeaseModel struct { } // BreakLease breaks a lock based on it's Lease ID -func (c Client) BreakLease(ctx context.Context, containerName string, input BreakLeaseInput) (resp BreakLeaseResponse, err error) { +func (c Client) BreakLease(ctx context.Context, containerName string, input BreakLeaseInput) (result BreakLeaseResponse, err error) { if containerName == "" { - return resp, fmt.Errorf("`containerName` cannot be an empty string") + return result, fmt.Errorf("`containerName` cannot be an empty string") } if input.LeaseID == "" { - return resp, fmt.Errorf("`input.LeaseID` cannot be an empty string") + return result, fmt.Errorf("`input.LeaseID` cannot be an empty string") } opts := client.RequestOptions{ @@ -56,27 +55,30 @@ func (c Client) BreakLease(ctx context.Context, containerName string, input Brea }, Path: fmt.Sprintf("/%s", containerName), } + req, err := c.Client.NewRequest(ctx, opts) if err != nil { err = fmt.Errorf("building request: %+v", err) return } - resp.HttpResponse, err = req.Execute(ctx) - if err != nil { - err = fmt.Errorf("executing request: %+v", err) - return - } - if resp.HttpResponse != nil { - leaseRaw := resp.HttpResponse.Header.Get("x-ms-lease-time") - if leaseRaw != "" { - if i, err := strconv.Atoi(leaseRaw); err == nil { - resp.Model = &BreakLeaseModel{ - LeaseTime: i, + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + + if resp.Header != nil { + if leaseTimeRaw := resp.Header.Get("x-ms-lease-time"); leaseTimeRaw != "" { + if leaseTime, err := strconv.Atoi(leaseTimeRaw); err == nil { + result.LeaseTime = leaseTime } } } } + if err != nil { + err = fmt.Errorf("executing request: %+v", err) + return + } return } diff --git a/storage/2023-11-03/blob/containers/lease_change.go b/storage/2023-11-03/blob/containers/lease_change.go index 6326507..1c1d732 100644 --- a/storage/2023-11-03/blob/containers/lease_change.go +++ b/storage/2023-11-03/blob/containers/lease_change.go @@ -15,8 +15,8 @@ type ChangeLeaseInput struct { } type ChangeLeaseResponse struct { - HttpResponse *client.Response - Model *ChangeLeaseModel + ChangeLeaseModel + HttpResponse *http.Response } type ChangeLeaseModel struct { @@ -24,15 +24,18 @@ type ChangeLeaseModel struct { } // ChangeLease changes the lock from one Lease ID to another Lease ID -func (c Client) ChangeLease(ctx context.Context, containerName string, input ChangeLeaseInput) (resp ChangeLeaseResponse, err error) { +func (c Client) ChangeLease(ctx context.Context, containerName string, input ChangeLeaseInput) (result ChangeLeaseResponse, err error) { if containerName == "" { - return resp, fmt.Errorf("`containerName` cannot be an empty string") + err = fmt.Errorf("`containerName` cannot be an empty string") + return } if input.ExistingLeaseID == "" { - return resp, fmt.Errorf("`input.ExistingLeaseID` cannot be an empty string") + err = fmt.Errorf("`input.ExistingLeaseID` cannot be an empty string") + return } if input.ProposedLeaseID == "" { - return resp, fmt.Errorf("`input.ProposedLeaseID` cannot be an empty string") + err = fmt.Errorf("`input.ProposedLeaseID` cannot be an empty string") + return } opts := client.RequestOptions{ @@ -47,23 +50,27 @@ func (c Client) ChangeLease(ctx context.Context, containerName string, input Cha }, Path: fmt.Sprintf("/%s", containerName), } + req, err := c.Client.NewRequest(ctx, opts) if err != nil { err = fmt.Errorf("building request: %+v", err) return } - resp.HttpResponse, err = req.Execute(ctx) + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + + if resp.Header != nil { + result.LeaseID = resp.Header.Get("x-ms-lease-id") + } + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return } - if resp.HttpResponse != nil { - resp.Model = &ChangeLeaseModel{ - LeaseID: resp.HttpResponse.Header.Get("x-ms-lease-id"), - } - } - return } diff --git a/storage/2023-11-03/blob/containers/lease_release.go b/storage/2023-11-03/blob/containers/lease_release.go index 8a2cf41..cdff4e2 100644 --- a/storage/2023-11-03/blob/containers/lease_release.go +++ b/storage/2023-11-03/blob/containers/lease_release.go @@ -14,16 +14,18 @@ type ReleaseLeaseInput struct { } type ReleaseLeaseResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response } // ReleaseLease releases the lock based on the Lease ID -func (c Client) ReleaseLease(ctx context.Context, containerName string, input ReleaseLeaseInput) (resp ReleaseLeaseResponse, err error) { +func (c Client) ReleaseLease(ctx context.Context, containerName string, input ReleaseLeaseInput) (result ReleaseLeaseResponse, err error) { if containerName == "" { - return resp, fmt.Errorf("`containerName` cannot be an empty string") + err = fmt.Errorf("`containerName` cannot be an empty string") + return } if input.LeaseId == "" { - return resp, fmt.Errorf("`input.LeaseId` cannot be an empty string") + err = fmt.Errorf("`input.LeaseId` cannot be an empty string") + return } opts := client.RequestOptions{ @@ -37,12 +39,18 @@ func (c Client) ReleaseLease(ctx context.Context, containerName string, input Re }, Path: fmt.Sprintf("/%s", containerName), } + req, err := c.Client.NewRequest(ctx, opts) if err != nil { err = fmt.Errorf("building request: %+v", err) return } - resp.HttpResponse, err = req.Execute(ctx) + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return diff --git a/storage/2023-11-03/blob/containers/lease_renew.go b/storage/2023-11-03/blob/containers/lease_renew.go index eda2029..38c9486 100644 --- a/storage/2023-11-03/blob/containers/lease_renew.go +++ b/storage/2023-11-03/blob/containers/lease_renew.go @@ -14,16 +14,18 @@ type RenewLeaseInput struct { } type RenewLeaseResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response } // RenewLease renews the lock based on the Lease ID -func (c Client) RenewLease(ctx context.Context, containerName string, input RenewLeaseInput) (resp RenewLeaseResponse, err error) { +func (c Client) RenewLease(ctx context.Context, containerName string, input RenewLeaseInput) (result RenewLeaseResponse, err error) { if containerName == "" { - return resp, fmt.Errorf("`containerName` cannot be an empty string") + err = fmt.Errorf("`containerName` cannot be an empty string") + return } if input.LeaseId == "" { - return resp, fmt.Errorf("`input.LeaseId` cannot be an empty string") + err = fmt.Errorf("`input.LeaseId` cannot be an empty string") + return } opts := client.RequestOptions{ @@ -37,12 +39,18 @@ func (c Client) RenewLease(ctx context.Context, containerName string, input Rene }, Path: fmt.Sprintf("/%s", containerName), } + req, err := c.Client.NewRequest(ctx, opts) if err != nil { err = fmt.Errorf("building request: %+v", err) return } - resp.HttpResponse, err = req.Execute(ctx) + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return diff --git a/storage/2023-11-03/blob/containers/lifecycle_test.go b/storage/2023-11-03/blob/containers/lifecycle_test.go index cc0b15a..e60d240 100644 --- a/storage/2023-11-03/blob/containers/lifecycle_test.go +++ b/storage/2023-11-03/blob/containers/lifecycle_test.go @@ -55,18 +55,15 @@ func TestContainerLifecycle(t *testing.T) { if err != nil { t.Fatalf("retrieving container: %+v", err) } - if container.Model == nil { - t.Fatalf("retrieving container: `model` was nil") - } - if container.Model.AccessLevel != Private { - t.Fatalf("Expected Access Level to be Private but got %q", container.Model.AccessLevel) + if container.AccessLevel != Private { + t.Fatalf("Expected Access Level to be Private but got %q", container.AccessLevel) } - if len(container.Model.MetaData) != 0 { - t.Fatalf("Expected MetaData to be empty but got: %s", container.Model.MetaData) + if len(container.MetaData) != 0 { + t.Fatalf("Expected MetaData to be empty but got: %s", container.MetaData) } - if container.Model.LeaseStatus != Unlocked { - t.Fatalf("Expected Container Lease to be Unlocked but was: %s", container.Model.LeaseStatus) + if container.LeaseStatus != Unlocked { + t.Fatalf("Expected Container Lease to be Unlocked but was: %s", container.LeaseStatus) } // then update the metadata @@ -87,17 +84,17 @@ func TestContainerLifecycle(t *testing.T) { if err != nil { t.Fatal(fmt.Errorf("Error re-retrieving: %s", err)) } - if len(container.Model.MetaData) != 1 { - t.Fatalf("Expected 1 item in the metadata but got: %s", container.Model.MetaData) + if len(container.MetaData) != 1 { + t.Fatalf("Expected 1 item in the metadata but got: %s", container.MetaData) } - if container.Model.MetaData["dont"] != "kill-my-vibe" { - t.Fatalf("Expected `kill-my-vibe` but got %q", container.Model.MetaData["dont"]) + if container.MetaData["dont"] != "kill-my-vibe" { + t.Fatalf("Expected `kill-my-vibe` but got %q", container.MetaData["dont"]) } - if container.Model.AccessLevel != Private { - t.Fatalf("Expected Access Level to be Private but got %q", container.Model.AccessLevel) + if container.AccessLevel != Private { + t.Fatalf("Expected Access Level to be Private but got %q", container.AccessLevel) } - if container.Model.LeaseStatus != Unlocked { - t.Fatalf("Expected Container Lease to be Unlocked but was: %s", container.Model.LeaseStatus) + if container.LeaseStatus != Unlocked { + t.Fatalf("Expected Container Lease to be Unlocked but was: %s", container.LeaseStatus) } // then update the ACL @@ -116,14 +113,14 @@ func TestContainerLifecycle(t *testing.T) { if err != nil { t.Fatal(fmt.Errorf("Error re-retrieving: %s", err)) } - if container.Model.AccessLevel != Blob { - t.Fatalf("Expected Access Level to be Blob but got %q", container.Model.AccessLevel) + if container.AccessLevel != Blob { + t.Fatalf("Expected Access Level to be Blob but got %q", container.AccessLevel) } - if len(container.Model.MetaData) != 1 { - t.Fatalf("Expected 1 item in the metadata but got: %s", container.Model.MetaData) + if len(container.MetaData) != 1 { + t.Fatalf("Expected 1 item in the metadata but got: %s", container.MetaData) } - if container.Model.LeaseStatus != Unlocked { - t.Fatalf("Expected Container Lease to be Unlocked but was: %s", container.Model.LeaseStatus) + if container.LeaseStatus != Unlocked { + t.Fatalf("Expected Container Lease to be Unlocked but was: %s", container.LeaseStatus) } // acquire a lease for 30s @@ -134,28 +131,22 @@ func TestContainerLifecycle(t *testing.T) { if err != nil { t.Fatalf("Error acquiring lease: %s", err) } - if acquireLeaseResp.Model == nil { - t.Fatalf("acquiring lease: `model` was nil") - } - t.Logf("[DEBUG] Lease ID: %s", acquireLeaseResp.Model.LeaseID) + t.Logf("[DEBUG] Lease ID: %s", acquireLeaseResp.LeaseID) // we should then be able to update the ID t.Logf("[DEBUG] Changing lease..") updateLeaseInput := ChangeLeaseInput{ - ExistingLeaseID: acquireLeaseResp.Model.LeaseID, + ExistingLeaseID: acquireLeaseResp.LeaseID, ProposedLeaseID: "aaaabbbb-aaaa-bbbb-cccc-aaaabbbbcccc", } updateLeaseResp, err := containersClient.ChangeLease(ctx, containerName, updateLeaseInput) if err != nil { t.Fatalf("changing lease: %+v", err) } - if updateLeaseResp.Model == nil { - t.Fatalf("changing lease: `model` was nil") - } // then renew it _, err = containersClient.RenewLease(ctx, containerName, RenewLeaseInput{ - LeaseId: updateLeaseResp.Model.LeaseID, + LeaseId: updateLeaseResp.LeaseID, }) if err != nil { t.Fatalf("Error renewing lease: %s", err) @@ -164,23 +155,20 @@ func TestContainerLifecycle(t *testing.T) { // and then give it a timeout breakPeriod := 20 breakLeaseInput := BreakLeaseInput{ - LeaseID: updateLeaseResp.Model.LeaseID, + LeaseID: updateLeaseResp.LeaseID, BreakPeriod: &breakPeriod, } breakLeaseResp, err := containersClient.BreakLease(ctx, containerName, breakLeaseInput) if err != nil { t.Fatalf("breaking lease: %+v", err) } - if breakLeaseResp.Model == nil { - t.Fatalf("breaking lease: `model` was nil") - } - if breakLeaseResp.Model.LeaseTime == 0 { - t.Fatalf("Lease broke immediately when should have waited: %d", breakLeaseResp.Model.LeaseTime) + if breakLeaseResp.LeaseTime == 0 { + t.Fatalf("Lease broke immediately when should have waited: %d", breakLeaseResp.LeaseTime) } // and finally ditch it _, err = containersClient.ReleaseLease(ctx, containerName, ReleaseLeaseInput{ - LeaseId: updateLeaseResp.Model.LeaseID, + LeaseId: updateLeaseResp.LeaseID, }) if err != nil { t.Fatalf("Error releasing lease: %s", err) @@ -192,12 +180,9 @@ func TestContainerLifecycle(t *testing.T) { if err != nil { t.Fatalf("listing blobs: %+v", err) } - if listResult.Model == nil { - t.Fatalf("listing blobs: `model` was nil") - } - if len(listResult.Model.Blobs.Blobs) != 0 { - t.Fatalf("Expected there to be no blobs in the container but got %d", len(listResult.Model.Blobs.Blobs)) + if len(listResult.Blobs.Blobs) != 0 { + t.Fatalf("Expected there to be no blobs in the container but got %d", len(listResult.Blobs.Blobs)) } t.Logf("[DEBUG] Deleting..") diff --git a/storage/2023-11-03/blob/containers/list_blobs.go b/storage/2023-11-03/blob/containers/list_blobs.go index f3bd467..86ddc7c 100644 --- a/storage/2023-11-03/blob/containers/list_blobs.go +++ b/storage/2023-11-03/blob/containers/list_blobs.go @@ -19,8 +19,9 @@ type ListBlobsInput struct { } type ListBlobsResponse struct { - HttpResponse *client.Response - Model *ListBlobsResult + ListBlobsResult + + HttpResponse *http.Response } type ListBlobsResult struct { @@ -80,12 +81,14 @@ type BlobPrefix struct { } // ListBlobs lists the blobs matching the specified query within the specified Container -func (c Client) ListBlobs(ctx context.Context, containerName string, input ListBlobsInput) (resp ListBlobsResponse, err error) { +func (c Client) ListBlobs(ctx context.Context, containerName string, input ListBlobsInput) (result ListBlobsResponse, err error) { if containerName == "" { - return resp, fmt.Errorf("`containerName` cannot be an empty string") + err = fmt.Errorf("`containerName` cannot be an empty string") + return } if input.MaxResults != nil && (*input.MaxResults <= 0 || *input.MaxResults > 5000) { - return resp, fmt.Errorf("`input.MaxResults` can either be nil or between 0 and 5000") + err = fmt.Errorf("`input.MaxResults` can either be nil or between 0 and 5000") + return } opts := client.RequestOptions{ ContentType: "application/xml; charset=utf-8", @@ -102,23 +105,28 @@ func (c Client) ListBlobs(ctx context.Context, containerName string, input ListB }, Path: fmt.Sprintf("/%s", containerName), } + req, err := c.Client.NewRequest(ctx, opts) if err != nil { err = fmt.Errorf("building request: %+v", err) return } - resp.HttpResponse, err = req.Execute(ctx) - if err != nil { - err = fmt.Errorf("executing request: %+v", err) - return - } - if resp.HttpResponse != nil { - if err = resp.HttpResponse.Unmarshal(&resp.Model); err != nil { - err = fmt.Errorf("unmarshaling response: %+v", err) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + + err = resp.Unmarshal(&result) + if err != nil { + err = fmt.Errorf("unmarshalling response: %+v", err) return } } + if err != nil { + err = fmt.Errorf("executing request: %+v", err) + return + } return } diff --git a/storage/2023-11-03/blob/containers/set_acl.go b/storage/2023-11-03/blob/containers/set_acl.go index 6420537..280ad4e 100644 --- a/storage/2023-11-03/blob/containers/set_acl.go +++ b/storage/2023-11-03/blob/containers/set_acl.go @@ -15,14 +15,15 @@ type SetAccessControlInput struct { } type SetAccessControlResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response } // SetAccessControl sets the Access Control for a Container without a Lease ID // NOTE: The SetAccessControl operation only supports Shared Key authorization. -func (c Client) SetAccessControl(ctx context.Context, containerName string, input SetAccessControlInput) (resp SetAccessControlResponse, err error) { +func (c Client) SetAccessControl(ctx context.Context, containerName string, input SetAccessControlInput) (result SetAccessControlResponse, err error) { if containerName == "" { - return resp, fmt.Errorf("`containerName` cannot be an empty string") + err = fmt.Errorf("`containerName` cannot be an empty string") + return } opts := client.RequestOptions{ @@ -37,12 +38,18 @@ func (c Client) SetAccessControl(ctx context.Context, containerName string, inpu }, Path: fmt.Sprintf("/%s", containerName), } + req, err := c.Client.NewRequest(ctx, opts) if err != nil { err = fmt.Errorf("building request: %+v", err) return } - resp.HttpResponse, err = req.Execute(ctx) + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return diff --git a/storage/2023-11-03/blob/containers/set_metadata.go b/storage/2023-11-03/blob/containers/set_metadata.go index 578c9a1..3f8bb07 100644 --- a/storage/2023-11-03/blob/containers/set_metadata.go +++ b/storage/2023-11-03/blob/containers/set_metadata.go @@ -16,16 +16,18 @@ type SetMetaDataInput struct { } type SetMetaDataResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response } // SetMetaData sets the specified MetaData on the Container without a Lease ID -func (c Client) SetMetaData(ctx context.Context, containerName string, input SetMetaDataInput) (resp SetMetaDataResponse, err error) { +func (c Client) SetMetaData(ctx context.Context, containerName string, input SetMetaDataInput) (result SetMetaDataResponse, err error) { if containerName == "" { - return resp, fmt.Errorf("`containerName` cannot be an empty string") + err = fmt.Errorf("`containerName` cannot be an empty string") + return } - if err := metadata.Validate(input.MetaData); err != nil { - return resp, fmt.Errorf("`input.MetaData` is not valid: %s", err) + if err = metadata.Validate(input.MetaData); err != nil { + err = fmt.Errorf("`input.MetaData` is not valid: %s", err) + return } opts := client.RequestOptions{ @@ -40,12 +42,18 @@ func (c Client) SetMetaData(ctx context.Context, containerName string, input Set }, Path: fmt.Sprintf("/%s", containerName), } + req, err := c.Client.NewRequest(ctx, opts) if err != nil { err = fmt.Errorf("building request: %+v", err) return } - resp.HttpResponse, err = req.Execute(ctx) + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return diff --git a/storage/2023-11-03/datalakestore/filesystems/create.go b/storage/2023-11-03/datalakestore/filesystems/create.go index d0d4bab..5bf1b66 100644 --- a/storage/2023-11-03/datalakestore/filesystems/create.go +++ b/storage/2023-11-03/datalakestore/filesystems/create.go @@ -18,14 +18,14 @@ type CreateInput struct { } type CreateResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response } // Create creates a Data Lake Store Gen2 FileSystem within a Storage Account -func (c Client) Create(ctx context.Context, fileSystemName string, input CreateInput) (resp CreateResponse, err error) { - +func (c Client) Create(ctx context.Context, fileSystemName string, input CreateInput) (result CreateResponse, err error) { if fileSystemName == "" { - return resp, fmt.Errorf("`fileSystemName` cannot be an empty string") + err = fmt.Errorf("`fileSystemName` cannot be an empty string") + return } opts := client.RequestOptions{ @@ -42,12 +42,16 @@ func (c Client) Create(ctx context.Context, fileSystemName string, input CreateI } req, err := c.Client.NewRequest(ctx, opts) - if err != nil { err = fmt.Errorf("building request: %+v", err) return } - resp.HttpResponse, err = req.Execute(ctx) + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return diff --git a/storage/2023-11-03/datalakestore/filesystems/delete.go b/storage/2023-11-03/datalakestore/filesystems/delete.go index a6d33b3..6900f28 100644 --- a/storage/2023-11-03/datalakestore/filesystems/delete.go +++ b/storage/2023-11-03/datalakestore/filesystems/delete.go @@ -9,14 +9,14 @@ import ( ) type DeleteResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response } // Delete deletes a Data Lake Store Gen2 FileSystem within a Storage Account -func (c Client) Delete(ctx context.Context, fileSystemName string) (resp DeleteResponse, err error) { - +func (c Client) Delete(ctx context.Context, fileSystemName string) (result DeleteResponse, err error) { if fileSystemName == "" { - return resp, fmt.Errorf("`fileSystemName` cannot be an empty string") + err = fmt.Errorf("`fileSystemName` cannot be an empty string") + return } opts := client.RequestOptions{ @@ -28,12 +28,18 @@ func (c Client) Delete(ctx context.Context, fileSystemName string) (resp DeleteR OptionsObject: fileSystemOptions{}, Path: fmt.Sprintf("/%s", fileSystemName), } + req, err := c.Client.NewRequest(ctx, opts) if err != nil { err = fmt.Errorf("building request: %+v", err) return } - resp.HttpResponse, err = req.Execute(ctx) + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return diff --git a/storage/2023-11-03/datalakestore/filesystems/helpers.go b/storage/2023-11-03/datalakestore/filesystems/helpers.go index 605ed42..7822a12 100644 --- a/storage/2023-11-03/datalakestore/filesystems/helpers.go +++ b/storage/2023-11-03/datalakestore/filesystems/helpers.go @@ -29,7 +29,7 @@ func parseProperties(input string) (*map[string]string, error) { // as such we can't string split on that -_- position := strings.Index(propertyRaw, "=") if position < 0 { - return nil, fmt.Errorf("Expected there to be an equals in the key value pair: %q", propertyRaw) + return nil, fmt.Errorf("expected an equal sign in the key value pair: %q", propertyRaw) } key := propertyRaw[0:position] diff --git a/storage/2023-11-03/datalakestore/filesystems/properties_get.go b/storage/2023-11-03/datalakestore/filesystems/properties_get.go index e8e4a67..47f394a 100644 --- a/storage/2023-11-03/datalakestore/filesystems/properties_get.go +++ b/storage/2023-11-03/datalakestore/filesystems/properties_get.go @@ -10,7 +10,7 @@ import ( ) type GetPropertiesResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response // A map of base64-encoded strings to store as user-defined properties with the File System // Note that items may only contain ASCII characters in the ISO-8859-1 character set. @@ -23,10 +23,10 @@ type GetPropertiesResponse struct { } // GetProperties gets the properties for a Data Lake Store Gen2 FileSystem within a Storage Account -func (c Client) GetProperties(ctx context.Context, fileSystemName string) (resp GetPropertiesResponse, err error) { - +func (c Client) GetProperties(ctx context.Context, fileSystemName string) (result GetPropertiesResponse, err error) { if fileSystemName == "" { - return resp, fmt.Errorf("`fileSystemName` cannot be an empty string") + err = fmt.Errorf("`fileSystemName` cannot be an empty string") + return } opts := client.RequestOptions{ @@ -45,24 +45,27 @@ func (c Client) GetProperties(ctx context.Context, fileSystemName string) (resp return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + + if resp.Header != nil { + propertiesRaw := resp.Header.Get("x-ms-properties") + var properties *map[string]string + properties, err = parseProperties(propertiesRaw) + if err != nil { + return + } + + result.Properties = *properties + result.NamespaceEnabled = strings.EqualFold(resp.Header.Get("x-ms-namespace-enabled"), "true") + } + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return } - if resp.HttpResponse != nil { - - propertiesRaw := resp.HttpResponse.Header.Get("x-ms-properties") - var properties *map[string]string - properties, err = parseProperties(propertiesRaw) - if err != nil { - return - } - - resp.Properties = *properties - resp.NamespaceEnabled = strings.EqualFold(resp.HttpResponse.Header.Get("x-ms-namespace-enabled"), "true") - - } return } diff --git a/storage/2023-11-03/datalakestore/filesystems/properties_set.go b/storage/2023-11-03/datalakestore/filesystems/properties_set.go index 82c259a..775807a 100644 --- a/storage/2023-11-03/datalakestore/filesystems/properties_set.go +++ b/storage/2023-11-03/datalakestore/filesystems/properties_set.go @@ -26,14 +26,14 @@ type SetPropertiesInput struct { } type SetPropertiesResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response } // SetProperties sets the Properties for a Data Lake Store Gen2 FileSystem within a Storage Account -func (c Client) SetProperties(ctx context.Context, fileSystemName string, input SetPropertiesInput) (resp SetPropertiesResponse, err error) { - +func (c Client) SetProperties(ctx context.Context, fileSystemName string, input SetPropertiesInput) (result SetPropertiesResponse, err error) { if fileSystemName == "" { - return resp, fmt.Errorf("`fileSystemName` cannot be an empty string") + err = fmt.Errorf("`fileSystemName` cannot be an empty string") + return } opts := client.RequestOptions{ @@ -52,12 +52,16 @@ func (c Client) SetProperties(ctx context.Context, fileSystemName string, input } req, err := c.Client.NewRequest(ctx, opts) - if err != nil { err = fmt.Errorf("building request: %+v", err) return } - resp.HttpResponse, err = req.Execute(ctx) + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return diff --git a/storage/2023-11-03/datalakestore/paths/create.go b/storage/2023-11-03/datalakestore/paths/create.go index c95ea17..8db9b66 100644 --- a/storage/2023-11-03/datalakestore/paths/create.go +++ b/storage/2023-11-03/datalakestore/paths/create.go @@ -19,14 +19,14 @@ type CreateInput struct { } type CreateResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response } // Create creates a Data Lake Store Gen2 Path within a Storage Account -func (c Client) Create(ctx context.Context, fileSystemName string, path string, input CreateInput) (resp CreateResponse, err error) { +func (c Client) Create(ctx context.Context, fileSystemName string, path string, input CreateInput) (result CreateResponse, err error) { if fileSystemName == "" { - return resp, fmt.Errorf("`fileSystemName` cannot be an empty string") + return result, fmt.Errorf("`fileSystemName` cannot be an empty string") } opts := client.RequestOptions{ @@ -46,12 +46,17 @@ func (c Client) Create(ctx context.Context, fileSystemName string, path string, if err != nil { err = fmt.Errorf("building request: %+v", err) - return resp, err + return result, err + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response } - resp.HttpResponse, err = req.Execute(ctx) if err != nil { err = fmt.Errorf("executing request: %+v", err) - return resp, err + return result, err } return diff --git a/storage/2023-11-03/datalakestore/paths/delete.go b/storage/2023-11-03/datalakestore/paths/delete.go index 4ea6e93..990be51 100644 --- a/storage/2023-11-03/datalakestore/paths/delete.go +++ b/storage/2023-11-03/datalakestore/paths/delete.go @@ -9,14 +9,14 @@ import ( ) type DeleteResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response } // Delete deletes a Data Lake Store Gen2 FileSystem within a Storage Account -func (c Client) Delete(ctx context.Context, fileSystemName string, path string) (resp DeleteResponse, err error) { +func (c Client) Delete(ctx context.Context, fileSystemName string, path string) (result DeleteResponse, err error) { if fileSystemName == "" { - return resp, fmt.Errorf("`fileSystemName` cannot be an empty string") + return result, fmt.Errorf("`fileSystemName` cannot be an empty string") } opts := client.RequestOptions{ @@ -33,7 +33,12 @@ func (c Client) Delete(ctx context.Context, fileSystemName string, path string) err = fmt.Errorf("building request: %+v", err) return } - resp.HttpResponse, err = req.Execute(ctx) + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return diff --git a/storage/2023-11-03/datalakestore/paths/helpers.go b/storage/2023-11-03/datalakestore/paths/helpers.go index e6ef6f4..08d893c 100644 --- a/storage/2023-11-03/datalakestore/paths/helpers.go +++ b/storage/2023-11-03/datalakestore/paths/helpers.go @@ -11,5 +11,5 @@ func parsePathResource(input string) (PathResource, error) { case "directory": return PathResourceDirectory, nil } - return "", fmt.Errorf("Unhandled path resource type %q", input) + return "", fmt.Errorf("unhandled path resource type %q", input) } diff --git a/storage/2023-11-03/datalakestore/paths/lifecycle_test.go b/storage/2023-11-03/datalakestore/paths/lifecycle_test.go index 2d1021d..47f2176 100644 --- a/storage/2023-11-03/datalakestore/paths/lifecycle_test.go +++ b/storage/2023-11-03/datalakestore/paths/lifecycle_test.go @@ -71,7 +71,7 @@ func TestLifecycle(t *testing.T) { } t.Logf("[DEBUG] Getting properties for folder 'test' ..") - props, err := pathsClient.GetProperties(ctx, fileSystemName, path, GetPropertiesInput{action: GetPropertiesActionGetAccessControl}) + props, err := pathsClient.GetProperties(ctx, fileSystemName, path, GetPropertiesInput{Action: GetPropertiesActionGetAccessControl}) if err != nil { t.Fatal(fmt.Errorf("error getting properties: %s", err)) } @@ -94,7 +94,7 @@ func TestLifecycle(t *testing.T) { } t.Logf("[DEBUG] Getting properties for folder 'test' (2) ..") - props, err = pathsClient.GetProperties(ctx, fileSystemName, path, GetPropertiesInput{action: GetPropertiesActionGetAccessControl}) + props, err = pathsClient.GetProperties(ctx, fileSystemName, path, GetPropertiesInput{Action: GetPropertiesActionGetAccessControl}) if err != nil { t.Fatal(fmt.Errorf("error getting properties (2): %s", err)) } @@ -108,7 +108,7 @@ func TestLifecycle(t *testing.T) { } t.Logf("[DEBUG] Getting properties for folder 'test' (3) ..") - props, err = pathsClient.GetProperties(ctx, fileSystemName, path, GetPropertiesInput{action: GetPropertiesActionGetAccessControl}) + props, err = pathsClient.GetProperties(ctx, fileSystemName, path, GetPropertiesInput{Action: GetPropertiesActionGetAccessControl}) if err == nil { t.Fatal(fmt.Errorf("didn't get error getting properties after deleting path (3)")) } diff --git a/storage/2023-11-03/datalakestore/paths/properties_get.go b/storage/2023-11-03/datalakestore/paths/properties_get.go index 2bb81af..f5dcb78 100644 --- a/storage/2023-11-03/datalakestore/paths/properties_get.go +++ b/storage/2023-11-03/datalakestore/paths/properties_get.go @@ -11,7 +11,7 @@ import ( ) type GetPropertiesResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response ETag string LastModified time.Time @@ -24,7 +24,7 @@ type GetPropertiesResponse struct { } type GetPropertiesInput struct { - action GetPropertiesAction + Action GetPropertiesAction } type GetPropertiesAction string @@ -35,9 +35,10 @@ const ( ) // GetProperties gets the properties for a Data Lake Store Gen2 Path in a FileSystem within a Storage Account -func (c Client) GetProperties(ctx context.Context, fileSystemName string, path string, input GetPropertiesInput) (resp GetPropertiesResponse, err error) { +func (c Client) GetProperties(ctx context.Context, fileSystemName string, path string, input GetPropertiesInput) (result GetPropertiesResponse, err error) { if fileSystemName == "" { - return resp, fmt.Errorf("`fileSystemName` cannot be an empty string") + err = fmt.Errorf("`fileSystemName` cannot be an empty string") + return } opts := client.RequestOptions{ @@ -47,7 +48,7 @@ func (c Client) GetProperties(ctx context.Context, fileSystemName string, path s }, HttpMethod: http.MethodHead, OptionsObject: getPropertyOptions{ - action: input.action, + action: input.Action, }, Path: fmt.Sprintf("/%s/%s", fileSystemName, path), } @@ -56,31 +57,36 @@ func (c Client) GetProperties(ctx context.Context, fileSystemName string, path s if err != nil { err = fmt.Errorf("building request: %+v", err) - return resp, err + return result, err } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + + if resp.Header != nil { + result.ResourceType = PathResource(resp.Header.Get("x-ms-resource-type")) + result.ETag = resp.Header.Get("ETag") + + if lastModifiedRaw := resp.Header.Get("Last-Modified"); lastModifiedRaw != "" { + lastModified, err := time.Parse(time.RFC1123, lastModifiedRaw) + if err != nil { + return GetPropertiesResponse{}, err + } + result.LastModified = lastModified + } + + result.Owner = resp.Header.Get("x-ms-owner") + result.Group = resp.Header.Get("x-ms-group") + result.ACL = resp.Header.Get("x-ms-acl") + } + } if err != nil { err = fmt.Errorf("executing request: %+v", err) - return resp, err + return result, err } - if resp.HttpResponse != nil { - resp.ResourceType = PathResource(resp.HttpResponse.Header.Get("x-ms-resource-type")) - resp.ETag = resp.HttpResponse.Header.Get("ETag") - - if lastModifiedRaw := resp.HttpResponse.Header.Get("Last-Modified"); lastModifiedRaw != "" { - lastModified, err := time.Parse(time.RFC1123, lastModifiedRaw) - if err != nil { - return GetPropertiesResponse{}, err - } - resp.LastModified = lastModified - } - - resp.Owner = resp.HttpResponse.Header.Get("x-ms-owner") - resp.Group = resp.HttpResponse.Header.Get("x-ms-group") - resp.ACL = resp.HttpResponse.Header.Get("x-ms-acl") - } return } diff --git a/storage/2023-11-03/datalakestore/paths/properties_set.go b/storage/2023-11-03/datalakestore/paths/properties_set.go index 055f199..826e0ef 100644 --- a/storage/2023-11-03/datalakestore/paths/properties_set.go +++ b/storage/2023-11-03/datalakestore/paths/properties_set.go @@ -24,14 +24,14 @@ type SetAccessControlInput struct { } type SetPropertiesResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response } // SetProperties sets the access control properties for a Data Lake Store Gen2 Path within a Storage Account File System -func (c Client) SetAccessControl(ctx context.Context, fileSystemName string, path string, input SetAccessControlInput) (resp SetPropertiesResponse, err error) { - +func (c Client) SetAccessControl(ctx context.Context, fileSystemName string, path string, input SetAccessControlInput) (result SetPropertiesResponse, err error) { if fileSystemName == "" { - return resp, fmt.Errorf("`fileSystemName` cannot be an empty string") + err = fmt.Errorf("`fileSystemName` cannot be an empty string") + return } opts := client.RequestOptions{ @@ -50,13 +50,17 @@ func (c Client) SetAccessControl(ctx context.Context, fileSystemName string, pat if err != nil { err = fmt.Errorf("building request: %+v", err) - return resp, err + return result, err } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) - return resp, err + return result, err } return diff --git a/storage/2023-11-03/file/directories/create.go b/storage/2023-11-03/file/directories/create.go index 7f63f9f..fdca3cf 100644 --- a/storage/2023-11-03/file/directories/create.go +++ b/storage/2023-11-03/file/directories/create.go @@ -28,26 +28,30 @@ type CreateDirectoryInput struct { } type CreateDirectoryResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response } // Create creates a new directory under the specified share or parent directory. -func (c Client) Create(ctx context.Context, shareName, path string, input CreateDirectoryInput) (resp CreateDirectoryResponse, err error) { +func (c Client) Create(ctx context.Context, shareName, path string, input CreateDirectoryInput) (result CreateDirectoryResponse, err error) { if shareName == "" { - return resp, fmt.Errorf("`shareName` cannot be an empty string") + err = fmt.Errorf("`shareName` cannot be an empty string") + return } if strings.ToLower(shareName) != shareName { - return resp, fmt.Errorf("`shareName` must be a lower-cased string") + err = fmt.Errorf("`shareName` must be a lower-cased string") + return } if err = metadata.Validate(input.MetaData); err != nil { - return resp, fmt.Errorf("`input.MetaData` is not valid: %s", err) + err = fmt.Errorf("`input.MetaData` is not valid: %s", err) + return } if path == "" { - return resp, fmt.Errorf("`path` cannot be an empty string") + err = fmt.Errorf("`path` cannot be an empty string") + return } opts := client.RequestOptions{ @@ -68,7 +72,11 @@ func (c Client) Create(ctx context.Context, shareName, path string, input Create return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return diff --git a/storage/2023-11-03/file/directories/delete.go b/storage/2023-11-03/file/directories/delete.go index fb96108..35b7298 100644 --- a/storage/2023-11-03/file/directories/delete.go +++ b/storage/2023-11-03/file/directories/delete.go @@ -10,23 +10,26 @@ import ( ) type DeleteResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response } // Delete removes the specified empty directory // Note that the directory must be empty before it can be deleted. -func (c Client) Delete(ctx context.Context, shareName, path string) (resp DeleteResponse, err error) { +func (c Client) Delete(ctx context.Context, shareName, path string) (result DeleteResponse, err error) { if shareName == "" { - return resp, fmt.Errorf("`shareName` cannot be an empty string") + err = fmt.Errorf("`shareName` cannot be an empty string") + return } if strings.ToLower(shareName) != shareName { - return resp, fmt.Errorf("`shareName` must be a lower-cased string") + err = fmt.Errorf("`shareName` must be a lower-cased string") + return } if path == "" { - return resp, fmt.Errorf("`path` cannot be an empty string") + err = fmt.Errorf("`path` cannot be an empty string") + return } opts := client.RequestOptions{ @@ -45,7 +48,11 @@ func (c Client) Delete(ctx context.Context, shareName, path string) (resp Delete return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return diff --git a/storage/2023-11-03/file/directories/get.go b/storage/2023-11-03/file/directories/get.go index 5c900c4..2aeb031 100644 --- a/storage/2023-11-03/file/directories/get.go +++ b/storage/2023-11-03/file/directories/get.go @@ -11,7 +11,7 @@ import ( ) type GetResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response // A set of name-value pairs that contain metadata for the directory. MetaData map[string]string @@ -23,17 +23,20 @@ type GetResponse struct { // Get returns all system properties for the specified directory, // and can also be used to check the existence of a directory. -func (c Client) Get(ctx context.Context, shareName, path string) (resp GetResponse, err error) { +func (c Client) Get(ctx context.Context, shareName, path string) (result GetResponse, err error) { if shareName == "" { - return resp, fmt.Errorf("`shareName` cannot be an empty string") + err = fmt.Errorf("`shareName` cannot be an empty string") + return } if strings.ToLower(shareName) != shareName { - return resp, fmt.Errorf("`shareName` must be a lower-cased string") + err = fmt.Errorf("`shareName` must be a lower-cased string") + return } if path == "" { - return resp, fmt.Errorf("`path` cannot be an empty string") + err = fmt.Errorf("`path` cannot be an empty string") + return } opts := client.RequestOptions{ @@ -52,18 +55,20 @@ func (c Client) Get(ctx context.Context, shareName, path string) (resp GetRespon return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + + if resp.Header != nil { + result.DirectoryMetaDataEncrypted = strings.EqualFold(resp.Header.Get("x-ms-server-encrypted"), "true") + result.MetaData = metadata.ParseFromHeaders(resp.Header) + } + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return } - if resp.HttpResponse != nil { - if resp.HttpResponse.Header != nil { - resp.MetaData = metadata.ParseFromHeaders(resp.HttpResponse.Header) - } - resp.DirectoryMetaDataEncrypted = strings.EqualFold(resp.HttpResponse.Header.Get("x-ms-server-encrypted"), "true") - } - return } diff --git a/storage/2023-11-03/file/directories/metadata_get.go b/storage/2023-11-03/file/directories/metadata_get.go index 1911d39..cfefeb5 100644 --- a/storage/2023-11-03/file/directories/metadata_get.go +++ b/storage/2023-11-03/file/directories/metadata_get.go @@ -12,23 +12,26 @@ import ( ) type GetMetaDataResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response MetaData map[string]string } // GetMetaData returns all user-defined metadata for the specified directory -func (c Client) GetMetaData(ctx context.Context, shareName, path string) (resp GetMetaDataResponse, err error) { +func (c Client) GetMetaData(ctx context.Context, shareName, path string) (result GetMetaDataResponse, err error) { if shareName == "" { - return resp, fmt.Errorf("`shareName` cannot be an empty string") + err = fmt.Errorf("`shareName` cannot be an empty string") + return } if strings.ToLower(shareName) != shareName { - return resp, fmt.Errorf("`shareName` must be a lower-cased string") + err = fmt.Errorf("`shareName` must be a lower-cased string") + return } if path == "" { - return resp, fmt.Errorf("`path` cannot be an empty string") + err = fmt.Errorf("`path` cannot be an empty string") + return } opts := client.RequestOptions{ @@ -47,18 +50,20 @@ func (c Client) GetMetaData(ctx context.Context, shareName, path string) (resp G return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + + if resp.Header != nil { + result.MetaData = metadata.ParseFromHeaders(resp.Header) + } + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return } - if resp.HttpResponse != nil { - if resp.HttpResponse.Header != nil { - resp.MetaData = metadata.ParseFromHeaders(resp.HttpResponse.Header) - } - } - return } diff --git a/storage/2023-11-03/file/directories/metadata_set.go b/storage/2023-11-03/file/directories/metadata_set.go index 965f5ff..8aa9097 100644 --- a/storage/2023-11-03/file/directories/metadata_set.go +++ b/storage/2023-11-03/file/directories/metadata_set.go @@ -12,7 +12,7 @@ import ( ) type SetMetaDataResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response } type SetMetaDataInput struct { @@ -20,22 +20,26 @@ type SetMetaDataInput struct { } // SetMetaData updates user defined metadata for the specified directory -func (c Client) SetMetaData(ctx context.Context, shareName, path string, input SetMetaDataInput) (resp SetMetaDataResponse, err error) { +func (c Client) SetMetaData(ctx context.Context, shareName, path string, input SetMetaDataInput) (result SetMetaDataResponse, err error) { if shareName == "" { - return resp, fmt.Errorf("`shareName` cannot be an empty string") + err = fmt.Errorf("`shareName` cannot be an empty string") + return } if strings.ToLower(shareName) != shareName { - return resp, fmt.Errorf("`shareName` must be a lower-cased string") + err = fmt.Errorf("`shareName` must be a lower-cased string") + return } - if err := metadata.Validate(input.MetaData); err != nil { - return resp, fmt.Errorf("`metadata` is not valid: %s", err) + if err = metadata.Validate(input.MetaData); err != nil { + err = fmt.Errorf("`metadata` is not valid: %s", err) + return } if path == "" { - return resp, fmt.Errorf("`path` cannot be an empty string") + err = fmt.Errorf("`path` cannot be an empty string") + return } opts := client.RequestOptions{ @@ -56,7 +60,11 @@ func (c Client) SetMetaData(ctx context.Context, shareName, path string, input S return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return diff --git a/storage/2023-11-03/file/files/copy.go b/storage/2023-11-03/file/files/copy.go index 577f95d..d835139 100644 --- a/storage/2023-11-03/file/files/copy.go +++ b/storage/2023-11-03/file/files/copy.go @@ -25,7 +25,7 @@ type CopyInput struct { } type CopyResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response // The CopyID, which can be passed to AbortCopy to abort the copy. CopyID string @@ -35,26 +35,31 @@ type CopyResponse struct { } // Copy copies a blob or file to a destination file within the storage account asynchronously. -func (c Client) Copy(ctx context.Context, shareName, path, fileName string, input CopyInput) (resp CopyResponse, err error) { +func (c Client) Copy(ctx context.Context, shareName, path, fileName string, input CopyInput) (result CopyResponse, err error) { if shareName == "" { - return resp, fmt.Errorf("`shareName` cannot be an empty string") + err = fmt.Errorf("`shareName` cannot be an empty string") + return } if strings.ToLower(shareName) != shareName { - return resp, fmt.Errorf("`shareName` must be a lower-cased string") + err = fmt.Errorf("`shareName` must be a lower-cased string") + return } if fileName == "" { - return resp, fmt.Errorf("`fileName` cannot be an empty string") + err = fmt.Errorf("`fileName` cannot be an empty string") + return } if input.CopySource == "" { - return resp, fmt.Errorf("`input.CopySource` cannot be an empty string") + err = fmt.Errorf("`input.CopySource` cannot be an empty string") + return } if err = metadata.Validate(input.MetaData); err != nil { - return resp, fmt.Errorf("`input.MetaData` is not valid: %s", err) + err = fmt.Errorf("`input.MetaData` is not valid: %s", err) + return } if path != "" { @@ -78,19 +83,22 @@ func (c Client) Copy(ctx context.Context, shareName, path, fileName string, inpu err = fmt.Errorf("building request: %+v", err) return } - resp.HttpResponse, err = req.Execute(ctx) + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + + if resp.Header != nil { + result.CopyID = resp.Header.Get("x-ms-copy-id") + result.CopySuccess = resp.Header.Get("x-ms-copy-status") + } + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return } - if resp.HttpResponse != nil { - if resp.HttpResponse.Header != nil { - resp.CopyID = resp.HttpResponse.Header.Get("x-ms-copy-id") - resp.CopySuccess = resp.HttpResponse.Header.Get("x-ms-copy-status") - } - } - return } diff --git a/storage/2023-11-03/file/files/copy_abort.go b/storage/2023-11-03/file/files/copy_abort.go index 5561160..191929b 100644 --- a/storage/2023-11-03/file/files/copy_abort.go +++ b/storage/2023-11-03/file/files/copy_abort.go @@ -15,26 +15,30 @@ type CopyAbortInput struct { } type CopyAbortResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response } // AbortCopy aborts a pending Copy File operation, and leaves a destination file with zero length and full metadata -func (c Client) AbortCopy(ctx context.Context, shareName, path, fileName string, input CopyAbortInput) (resp CopyAbortResponse, err error) { +func (c Client) AbortCopy(ctx context.Context, shareName, path, fileName string, input CopyAbortInput) (result CopyAbortResponse, err error) { if shareName == "" { - return resp, fmt.Errorf("`shareName` cannot be an empty string") + err = fmt.Errorf("`shareName` cannot be an empty string") + return } if strings.ToLower(shareName) != shareName { - return resp, fmt.Errorf("`shareName` must be a lower-cased string") + err = fmt.Errorf("`shareName` must be a lower-cased string") + return } if fileName == "" { - return resp, fmt.Errorf("`fileName` cannot be an empty string") + err = fmt.Errorf("`fileName` cannot be an empty string") + return } if input.copyID == "" { - return resp, fmt.Errorf("`copyID` cannot be an empty string") + err = fmt.Errorf("`copyID` cannot be an empty string") + return } if path != "" { @@ -59,7 +63,11 @@ func (c Client) AbortCopy(ctx context.Context, shareName, path, fileName string, return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return diff --git a/storage/2023-11-03/file/files/copy_wait.go b/storage/2023-11-03/file/files/copy_wait.go index 1ccb5f3..9223f54 100644 --- a/storage/2023-11-03/file/files/copy_wait.go +++ b/storage/2023-11-03/file/files/copy_wait.go @@ -9,20 +9,20 @@ import ( ) // CopyAndWait is a convenience method which doesn't exist in the API, which copies the file and then waits for the copy to complete -func (c Client) CopyAndWait(ctx context.Context, shareName, path, fileName string, input CopyInput) (resp CopyResponse, err error) { - copy, e := c.Copy(ctx, shareName, path, fileName, input) +func (c Client) CopyAndWait(ctx context.Context, shareName, path, fileName string, input CopyInput) (result CopyResponse, err error) { + fileCopy, e := c.Copy(ctx, shareName, path, fileName, input) if err != nil { - resp.HttpResponse = copy.HttpResponse - err = fmt.Errorf("error copying: %s", e) + result.HttpResponse = fileCopy.HttpResponse + err = fmt.Errorf("copying: %s", e) return } - resp.CopyID = copy.CopyID + result.CopyID = fileCopy.CopyID pollerType := NewCopyAndWaitPoller(&c, shareName, path, fileName) poller := pollers.NewPoller(pollerType, 10*time.Second, pollers.DefaultNumberOfDroppedConnectionsToAllow) - if err := poller.PollUntilDone(ctx); err != nil { - return resp, fmt.Errorf("waiting for file to copy: %+v", err) + if err = poller.PollUntilDone(ctx); err != nil { + return result, fmt.Errorf("waiting for file to copy: %+v", err) } return diff --git a/storage/2023-11-03/file/files/create.go b/storage/2023-11-03/file/files/create.go index 7c08a85..5fb8e97 100644 --- a/storage/2023-11-03/file/files/create.go +++ b/storage/2023-11-03/file/files/create.go @@ -51,25 +51,29 @@ type CreateInput struct { } type CreateResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response } // Create creates a new file or replaces a file. -func (c Client) Create(ctx context.Context, shareName, path, fileName string, input CreateInput) (resp CreateResponse, err error) { +func (c Client) Create(ctx context.Context, shareName, path, fileName string, input CreateInput) (result CreateResponse, err error) { if shareName == "" { - return resp, fmt.Errorf("`shareName` cannot be an empty string") + err = fmt.Errorf("`shareName` cannot be an empty string") + return } if strings.ToLower(shareName) != shareName { - return resp, fmt.Errorf("`shareName` must be a lower-cased string") + err = fmt.Errorf("`shareName` must be a lower-cased string") + return } if fileName == "" { - return resp, fmt.Errorf("`fileName` cannot be an empty string") + err = fmt.Errorf("`fileName` cannot be an empty string") + return } if err = metadata.Validate(input.MetaData); err != nil { - return resp, fmt.Errorf("`input.MetaData` is not valid: %s", err) + err = fmt.Errorf("`input.MetaData` is not valid: %s", err) + return } if path != "" { @@ -94,7 +98,11 @@ func (c Client) Create(ctx context.Context, shareName, path, fileName string, in return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return diff --git a/storage/2023-11-03/file/files/delete.go b/storage/2023-11-03/file/files/delete.go index d5e3240..f3841fa 100644 --- a/storage/2023-11-03/file/files/delete.go +++ b/storage/2023-11-03/file/files/delete.go @@ -10,22 +10,25 @@ import ( ) type DeleteResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response } // Delete immediately deletes the file from the File Share. -func (c Client) Delete(ctx context.Context, shareName, path, fileName string) (resp DeleteResponse, err error) { +func (c Client) Delete(ctx context.Context, shareName, path, fileName string) (result DeleteResponse, err error) { if shareName == "" { - return resp, fmt.Errorf("`shareName` cannot be an empty string") + err = fmt.Errorf("`shareName` cannot be an empty string") + return } if strings.ToLower(shareName) != shareName { - return resp, fmt.Errorf("`shareName` must be a lower-cased string") + err = fmt.Errorf("`shareName` must be a lower-cased string") + return } if fileName == "" { - return resp, fmt.Errorf("`fileName` cannot be an empty string") + err = fmt.Errorf("`fileName` cannot be an empty string") + return } if path != "" { @@ -48,7 +51,11 @@ func (c Client) Delete(ctx context.Context, shareName, path, fileName string) (r return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return diff --git a/storage/2023-11-03/file/files/metadata_get.go b/storage/2023-11-03/file/files/metadata_get.go index 3e0fbad..a4d1cc9 100644 --- a/storage/2023-11-03/file/files/metadata_get.go +++ b/storage/2023-11-03/file/files/metadata_get.go @@ -12,23 +12,26 @@ import ( ) type GetMetaDataResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response MetaData map[string]string } // GetMetaData returns the MetaData for the specified File. -func (c Client) GetMetaData(ctx context.Context, shareName, path, fileName string) (resp GetMetaDataResponse, err error) { +func (c Client) GetMetaData(ctx context.Context, shareName, path, fileName string) (result GetMetaDataResponse, err error) { if shareName == "" { - return resp, fmt.Errorf("`shareName` cannot be an empty string") + err = fmt.Errorf("`shareName` cannot be an empty string") + return } if strings.ToLower(shareName) != shareName { - return resp, fmt.Errorf("`shareName` must be a lower-cased string") + err = fmt.Errorf("`shareName` must be a lower-cased string") + return } if fileName == "" { - return resp, fmt.Errorf("`fileName` cannot be an empty string") + err = fmt.Errorf("`fileName` cannot be an empty string") + return } if path != "" { @@ -51,18 +54,20 @@ func (c Client) GetMetaData(ctx context.Context, shareName, path, fileName strin return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + + if resp.Header != nil { + result.MetaData = metadata.ParseFromHeaders(resp.Header) + } + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return } - if resp.HttpResponse != nil { - if resp.HttpResponse.Header != nil { - resp.MetaData = metadata.ParseFromHeaders(resp.HttpResponse.Header) - } - } - return } diff --git a/storage/2023-11-03/file/files/metadata_set.go b/storage/2023-11-03/file/files/metadata_set.go index 4087ef5..3a51a10 100644 --- a/storage/2023-11-03/file/files/metadata_set.go +++ b/storage/2023-11-03/file/files/metadata_set.go @@ -12,7 +12,7 @@ import ( ) type SetMetaDataResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response } type SetMetaDataInput struct { @@ -20,21 +20,25 @@ type SetMetaDataInput struct { } // SetMetaData updates the specified File to have the specified MetaData. -func (c Client) SetMetaData(ctx context.Context, shareName, path, fileName string, input SetMetaDataInput) (resp SetMetaDataResponse, err error) { +func (c Client) SetMetaData(ctx context.Context, shareName, path, fileName string, input SetMetaDataInput) (result SetMetaDataResponse, err error) { if shareName == "" { - return resp, fmt.Errorf("`shareName` cannot be an empty string") + err = fmt.Errorf("`shareName` cannot be an empty string") + return } if strings.ToLower(shareName) != shareName { - return resp, fmt.Errorf("`shareName` must be a lower-cased string") + err = fmt.Errorf("`shareName` must be a lower-cased string") + return } if fileName == "" { - return resp, fmt.Errorf("`fileName` cannot be an empty string") + err = fmt.Errorf("`fileName` cannot be an empty string") + return } if err = metadata.Validate(input.MetaData); err != nil { - return resp, fmt.Errorf("`input.MetaData` is not valid: %s", err) + err = fmt.Errorf("`input.MetaData` is not valid: %s", err) + return } if path != "" { @@ -59,7 +63,11 @@ func (c Client) SetMetaData(ctx context.Context, shareName, path, fileName strin return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return diff --git a/storage/2023-11-03/file/files/properties_get.go b/storage/2023-11-03/file/files/properties_get.go index 6a21f77..2ea1f63 100644 --- a/storage/2023-11-03/file/files/properties_get.go +++ b/storage/2023-11-03/file/files/properties_get.go @@ -12,7 +12,7 @@ import ( ) type GetResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response CacheControl string ContentDisposition string @@ -33,17 +33,20 @@ type GetResponse struct { } // GetProperties returns the Properties for the specified file -func (c Client) GetProperties(ctx context.Context, shareName, path, fileName string) (resp GetResponse, err error) { +func (c Client) GetProperties(ctx context.Context, shareName, path, fileName string) (result GetResponse, err error) { if shareName == "" { - return resp, fmt.Errorf("`shareName` cannot be an empty string") + err = fmt.Errorf("`shareName` cannot be an empty string") + return } if strings.ToLower(shareName) != shareName { - return resp, fmt.Errorf("`shareName` must be a lower-cased string") + err = fmt.Errorf("`shareName` must be a lower-cased string") + return } if fileName == "" { - return resp, fmt.Errorf("`fileName` cannot be an empty string") + err = fmt.Errorf("`fileName` cannot be an empty string") + return } if path != "" { @@ -66,40 +69,44 @@ func (c Client) GetProperties(ctx context.Context, shareName, path, fileName str return } - resp.HttpResponse, err = req.Execute(ctx) - if err != nil { - err = fmt.Errorf("executing request: %+v", err) - return - } + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response - if resp.HttpResponse != nil { - if resp.HttpResponse.Header != nil { - resp.CacheControl = resp.HttpResponse.Header.Get("Cache-Control") - resp.ContentDisposition = resp.HttpResponse.Header.Get("Content-Disposition") - resp.ContentEncoding = resp.HttpResponse.Header.Get("Content-Encoding") - resp.ContentLanguage = resp.HttpResponse.Header.Get("Content-Language") - resp.ContentMD5 = resp.HttpResponse.Header.Get("Content-MD5") - resp.ContentType = resp.HttpResponse.Header.Get("Content-Type") - resp.CopyID = resp.HttpResponse.Header.Get("x-ms-copy-id") - resp.CopyProgress = resp.HttpResponse.Header.Get("x-ms-copy-progress") - resp.CopySource = resp.HttpResponse.Header.Get("x-ms-copy-source") - resp.CopyStatus = resp.HttpResponse.Header.Get("x-ms-copy-status") - resp.CopyStatusDescription = resp.HttpResponse.Header.Get("x-ms-copy-status-description") - resp.CopyCompletionTime = resp.HttpResponse.Header.Get("x-ms-copy-completion-time") - resp.Encrypted = strings.EqualFold(resp.HttpResponse.Header.Get("x-ms-server-encrypted"), "true") - resp.MetaData = metadata.ParseFromHeaders(resp.HttpResponse.Header) + if resp.Header != nil { + result.CacheControl = resp.Header.Get("Cache-Control") + result.ContentDisposition = resp.Header.Get("Content-Disposition") + result.ContentEncoding = resp.Header.Get("Content-Encoding") + result.ContentLanguage = resp.Header.Get("Content-Language") + result.ContentMD5 = resp.Header.Get("Content-MD5") + result.ContentType = resp.Header.Get("Content-Type") + result.CopyCompletionTime = resp.Header.Get("x-ms-copy-completion-time") + result.CopyID = resp.Header.Get("x-ms-copy-id") + result.CopyProgress = resp.Header.Get("x-ms-copy-progress") + result.CopySource = resp.Header.Get("x-ms-copy-source") + result.CopyStatus = resp.Header.Get("x-ms-copy-status") + result.CopyStatusDescription = resp.Header.Get("x-ms-copy-status-description") + result.Encrypted = strings.EqualFold(resp.Header.Get("x-ms-server-encrypted"), "true") + result.MetaData = metadata.ParseFromHeaders(resp.Header) - contentLengthRaw := resp.HttpResponse.Header.Get("Content-Length") + contentLengthRaw := resp.Header.Get("Content-Length") if contentLengthRaw != "" { - contentLength, err := strconv.Atoi(contentLengthRaw) + var contentLength int + contentLength, err = strconv.Atoi(contentLengthRaw) if err != nil { - return resp, fmt.Errorf("error parsing %q for Content-Length as an integer: %s", contentLengthRaw, err) + err = fmt.Errorf("parsing `Content-Length` header value %q: %s", contentLengthRaw, err) + return } contentLengthI64 := int64(contentLength) - resp.ContentLength = &contentLengthI64 + result.ContentLength = &contentLengthI64 } } } + if err != nil { + err = fmt.Errorf("executing request: %+v", err) + return + } return } diff --git a/storage/2023-11-03/file/files/properties_set.go b/storage/2023-11-03/file/files/properties_set.go index 0e2c547..83bd841 100644 --- a/storage/2023-11-03/file/files/properties_set.go +++ b/storage/2023-11-03/file/files/properties_set.go @@ -68,21 +68,24 @@ type SetPropertiesInput struct { } type SetPropertiesResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response } // SetProperties sets the specified properties on the specified File -func (c Client) SetProperties(ctx context.Context, shareName, path, fileName string, input SetPropertiesInput) (resp SetPropertiesResponse, err error) { +func (c Client) SetProperties(ctx context.Context, shareName, path, fileName string, input SetPropertiesInput) (result SetPropertiesResponse, err error) { if shareName == "" { - return resp, fmt.Errorf("`shareName` cannot be an empty string") + err = fmt.Errorf("`shareName` cannot be an empty string") + return } if strings.ToLower(shareName) != shareName { - return resp, fmt.Errorf("`shareName` must be a lower-cased string") + err = fmt.Errorf("`shareName` must be a lower-cased string") + return } if fileName == "" { - return resp, fmt.Errorf("`fileName` cannot be an empty string") + err = fmt.Errorf("`fileName` cannot be an empty string") + return } if path != "" { @@ -107,7 +110,11 @@ func (c Client) SetProperties(ctx context.Context, shareName, path, fileName str return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return diff --git a/storage/2023-11-03/file/files/range_clear.go b/storage/2023-11-03/file/files/range_clear.go index c2391a1..0a1e814 100644 --- a/storage/2023-11-03/file/files/range_clear.go +++ b/storage/2023-11-03/file/files/range_clear.go @@ -16,30 +16,35 @@ type ClearByteRangeInput struct { } type ClearByteRangeResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response } // ClearByteRange clears the specified Byte Range from within the specified File -func (c Client) ClearByteRange(ctx context.Context, shareName, path, fileName string, input ClearByteRangeInput) (resp ClearByteRangeResponse, err error) { +func (c Client) ClearByteRange(ctx context.Context, shareName, path, fileName string, input ClearByteRangeInput) (result ClearByteRangeResponse, err error) { if shareName == "" { - return resp, fmt.Errorf("`shareName` cannot be an empty string") + err = fmt.Errorf("`shareName` cannot be an empty string") + return } if strings.ToLower(shareName) != shareName { - return resp, fmt.Errorf("`shareName` must be a lower-cased string") + err = fmt.Errorf("`shareName` must be a lower-cased string") + return } if fileName == "" { - return resp, fmt.Errorf("`fileName` cannot be an empty string") + err = fmt.Errorf("`fileName` cannot be an empty string") + return } if input.StartBytes < 0 { - return resp, fmt.Errorf("`input.StartBytes` must be greater or equal to 0") + err = fmt.Errorf("`input.StartBytes` must be greater or equal to 0") + return } if input.EndBytes <= 0 { - return resp, fmt.Errorf("`input.EndBytes` must be greater than 0") + err = fmt.Errorf("`input.EndBytes` must be greater than 0") + return } if path != "" { @@ -64,7 +69,11 @@ func (c Client) ClearByteRange(ctx context.Context, shareName, path, fileName st return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return diff --git a/storage/2023-11-03/file/files/range_get.go b/storage/2023-11-03/file/files/range_get.go index 90a1089..b605662 100644 --- a/storage/2023-11-03/file/files/range_get.go +++ b/storage/2023-11-03/file/files/range_get.go @@ -17,40 +17,47 @@ type GetByteRangeInput struct { } type GetByteRangeResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response Contents []byte } // GetByteRange returns the specified Byte Range from the specified File. -func (c Client) GetByteRange(ctx context.Context, shareName, path, fileName string, input GetByteRangeInput) (resp GetByteRangeResponse, err error) { +func (c Client) GetByteRange(ctx context.Context, shareName, path, fileName string, input GetByteRangeInput) (result GetByteRangeResponse, err error) { if shareName == "" { - return resp, fmt.Errorf("`shareName` cannot be an empty string") + err = fmt.Errorf("`shareName` cannot be an empty string") + return } if strings.ToLower(shareName) != shareName { - return resp, fmt.Errorf("`shareName` must be a lower-cased string") + err = fmt.Errorf("`shareName` must be a lower-cased string") + return } if fileName == "" { - return resp, fmt.Errorf("`fileName` cannot be an empty string") + err = fmt.Errorf("`fileName` cannot be an empty string") + return } if input.StartBytes < 0 { - return resp, fmt.Errorf("`input.StartBytes` must be greater or equal to 0") + err = fmt.Errorf("`input.StartBytes` must be greater or equal to 0") + return } if input.EndBytes <= 0 { - return resp, fmt.Errorf("`input.EndBytes` must be greater than 0") + err = fmt.Errorf("`input.EndBytes` must be greater than 0") + return } expectedBytes := input.EndBytes - input.StartBytes if expectedBytes < (4 * 1024) { - return resp, fmt.Errorf("requested Byte Range must be at least 4KB") + err = fmt.Errorf("requested Byte Range must be at least 4KB") + return } if expectedBytes > (4 * 1024 * 1024) { - return resp, fmt.Errorf("requested Byte Range must be at most 4MB") + err = fmt.Errorf("requested Byte Range must be at most 4MB") + return } if path != "" { @@ -75,20 +82,21 @@ func (c Client) GetByteRange(ctx context.Context, shareName, path, fileName stri return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + + if result.Contents, err = io.ReadAll(resp.Body); err != nil { + err = fmt.Errorf("reading response body: %+v", err) + return + } + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return } - if resp.HttpResponse != nil { - bytes, err := io.ReadAll(resp.HttpResponse.Body) - if err != nil { - return resp, fmt.Errorf("reading response body: %v", err) - } - resp.Contents = bytes - } - return } diff --git a/storage/2023-11-03/file/files/range_get_file.go b/storage/2023-11-03/file/files/range_get_file.go index f818526..0858943 100644 --- a/storage/2023-11-03/file/files/range_get_file.go +++ b/storage/2023-11-03/file/files/range_get_file.go @@ -5,10 +5,9 @@ import ( "fmt" "log" "math" + "net/http" "runtime" "sync" - - "github.com/hashicorp/go-azure-sdk/sdk/client" ) type GetFileInput struct { @@ -16,18 +15,18 @@ type GetFileInput struct { } type GetFileResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response OutputBytes []byte } // GetFile is a helper method to download a file by chunking it automatically -func (c Client) GetFile(ctx context.Context, shareName, path, fileName string, input GetFileInput) (resp GetFileResponse, err error) { +func (c Client) GetFile(ctx context.Context, shareName, path, fileName string, input GetFileInput) (result GetFileResponse, err error) { // first look up the file and check out how many bytes it is file, e := c.GetProperties(ctx, shareName, path, fileName) if err != nil { - resp.HttpResponse = file.HttpResponse + result.HttpResponse = file.HttpResponse err = e return } @@ -37,7 +36,7 @@ func (c Client) GetFile(ctx context.Context, shareName, path, fileName string, i return } - resp.HttpResponse = file.HttpResponse + result.HttpResponse = file.HttpResponse length := *file.ContentLength chunkSize := int64(4 * 1024 * 1024) // 4MB @@ -95,7 +94,7 @@ func (c Client) GetFile(ctx context.Context, shareName, path, fileName string, i copy(output[v.startBytes:v.endBytes], v.bytes) } - resp.OutputBytes = output + result.OutputBytes = output return } diff --git a/storage/2023-11-03/file/files/range_put.go b/storage/2023-11-03/file/files/range_put.go index 7588f8b..58e6f9b 100644 --- a/storage/2023-11-03/file/files/range_put.go +++ b/storage/2023-11-03/file/files/range_put.go @@ -23,39 +23,45 @@ type PutByteRangeInput struct { } type PutRangeResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response } // PutByteRange puts the specified Byte Range in the specified File. -func (c Client) PutByteRange(ctx context.Context, shareName, path, fileName string, input PutByteRangeInput) (resp PutRangeResponse, err error) { - +func (c Client) PutByteRange(ctx context.Context, shareName, path, fileName string, input PutByteRangeInput) (result PutRangeResponse, err error) { if shareName == "" { - return resp, fmt.Errorf("`shareName` cannot be an empty string") + err = fmt.Errorf("`shareName` cannot be an empty string") + return } if strings.ToLower(shareName) != shareName { - return resp, fmt.Errorf("`shareName` must be a lower-cased string") + err = fmt.Errorf("`shareName` must be a lower-cased string") + return } if fileName == "" { - return resp, fmt.Errorf("`fileName` cannot be an empty string") + err = fmt.Errorf("`fileName` cannot be an empty string") + return } if input.StartBytes < 0 { - return resp, fmt.Errorf("`input.StartBytes` must be greater or equal to 0") + err = fmt.Errorf("`input.StartBytes` must be greater or equal to 0") + return } if input.EndBytes <= 0 { - return resp, fmt.Errorf("`input.EndBytes` must be greater than 0") + err = fmt.Errorf("`input.EndBytes` must be greater than 0") + return } expectedBytes := input.EndBytes - input.StartBytes actualBytes := len(input.Content) if expectedBytes != int64(actualBytes) { - return resp, fmt.Errorf(fmt.Sprintf("The specified byte-range (%d) didn't match the content size (%d).", expectedBytes, actualBytes)) + err = fmt.Errorf(fmt.Sprintf("The specified byte-range (%d) didn't match the content size (%d).", expectedBytes, actualBytes)) + return } if expectedBytes > (4 * 1024 * 1024) { - return resp, fmt.Errorf("specified Byte Range must be at most 4MB") + err = fmt.Errorf("specified Byte Range must be at most 4MB") + return } if path != "" { @@ -82,7 +88,11 @@ func (c Client) PutByteRange(ctx context.Context, shareName, path, fileName stri req.Body = io.NopCloser(bytes.NewReader(input.Content)) req.ContentLength = int64(len(input.Content)) - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return diff --git a/storage/2023-11-03/file/files/range_put_file.go b/storage/2023-11-03/file/files/range_put_file.go index cad6f55..660122c 100644 --- a/storage/2023-11-03/file/files/range_put_file.go +++ b/storage/2023-11-03/file/files/range_put_file.go @@ -66,7 +66,7 @@ func (c Client) PutFile(ctx context.Context, shareName, path, fileName string, f // TODO: we should switch to hashicorp/multi-error here if len(errors) > 0 { - return fmt.Errorf("Error uploading file: %s", <-errors) + return fmt.Errorf("uploading file: %s", <-errors) } return nil @@ -94,7 +94,7 @@ func (c Client) uploadChunk(ctx context.Context, shareName, path, fileName strin _, err = file.ReadAt(bytes, startBytes) if err != nil { if err != io.EOF { - return result, fmt.Errorf("Error reading bytes: %s", err) + return result, fmt.Errorf("reading bytes: %s", err) } } @@ -105,7 +105,7 @@ func (c Client) uploadChunk(ctx context.Context, shareName, path, fileName strin } result, err = c.PutByteRange(ctx, shareName, path, fileName, putBytesInput) if err != nil { - return result, fmt.Errorf("error putting bytes: %s", err) + return result, fmt.Errorf("putting bytes: %s", err) } return diff --git a/storage/2023-11-03/file/files/ranges_list.go b/storage/2023-11-03/file/files/ranges_list.go index 9a67cab..0b89e6c 100644 --- a/storage/2023-11-03/file/files/ranges_list.go +++ b/storage/2023-11-03/file/files/ranges_list.go @@ -11,7 +11,7 @@ import ( ) type ListRangesResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response Ranges []Range `xml:"Range"` } @@ -22,22 +22,25 @@ type Range struct { } // ListRanges returns the list of valid ranges for the specified File. -func (c Client) ListRanges(ctx context.Context, shareName, path, fileName string) (resp ListRangesResponse, err error) { - +func (c Client) ListRanges(ctx context.Context, shareName, path, fileName string) (result ListRangesResponse, err error) { if shareName == "" { - return resp, fmt.Errorf("`shareName` cannot be an empty string") + err = fmt.Errorf("`shareName` cannot be an empty string") + return } if strings.ToLower(shareName) != shareName { - return resp, fmt.Errorf("`shareName` must be a lower-cased string") + err = fmt.Errorf("`shareName` must be a lower-cased string") + return } if path == "" { - return resp, fmt.Errorf("`path` cannot be an empty string") + err = fmt.Errorf("`path` cannot be an empty string") + return } if fileName == "" { - return resp, fmt.Errorf("`fileName` cannot be an empty string") + err = fmt.Errorf("`fileName` cannot be an empty string") + return } if path != "" { @@ -60,16 +63,22 @@ func (c Client) ListRanges(ctx context.Context, shareName, path, fileName string return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + + err = resp.Unmarshal(&result) + if err != nil { + err = fmt.Errorf("unmarshalling response: %+v", err) + return + } + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return } - if resp.HttpResponse != nil { - resp.HttpResponse.Unmarshal(&resp) - } - return } diff --git a/storage/2023-11-03/file/shares/acl_get.go b/storage/2023-11-03/file/shares/acl_get.go index 56aa641..8add483 100644 --- a/storage/2023-11-03/file/shares/acl_get.go +++ b/storage/2023-11-03/file/shares/acl_get.go @@ -11,19 +11,20 @@ import ( ) type GetACLResult struct { - HttpResponse *client.Response + HttpResponse *http.Response SignedIdentifiers []SignedIdentifier `xml:"SignedIdentifier"` } // GetACL get the Access Control List for the specified Storage Share -func (c Client) GetACL(ctx context.Context, shareName string) (resp GetACLResult, err error) { - +func (c Client) GetACL(ctx context.Context, shareName string) (result GetACLResult, err error) { if shareName == "" { - return resp, fmt.Errorf("`shareName` cannot be an empty string") + err = fmt.Errorf("`shareName` cannot be an empty string") + return } if strings.ToLower(shareName) != shareName { - return resp, fmt.Errorf("`shareName` must be a lower-cased string") + err = fmt.Errorf("`shareName` must be a lower-cased string") + return } opts := client.RequestOptions{ @@ -42,18 +43,22 @@ func (c Client) GetACL(ctx context.Context, shareName string) (resp GetACLResult return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + + err = resp.Unmarshal(&result) + if err != nil { + err = fmt.Errorf("unmarshalling response: %+v", err) + return + } + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return } - if resp.HttpResponse != nil { - err = resp.HttpResponse.Unmarshal(&resp) - if err != nil { - return resp, fmt.Errorf("unmarshalling response: %v", err) - } - } return } diff --git a/storage/2023-11-03/file/shares/acl_set.go b/storage/2023-11-03/file/shares/acl_set.go index 33b7c84..58e87bc 100644 --- a/storage/2023-11-03/file/shares/acl_set.go +++ b/storage/2023-11-03/file/shares/acl_set.go @@ -15,7 +15,7 @@ import ( ) type SetAclResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response } type SetAclInput struct { @@ -25,14 +25,15 @@ type SetAclInput struct { } // SetACL sets the specified Access Control List on the specified Storage Share -func (c Client) SetACL(ctx context.Context, shareName string, input SetAclInput) (resp SetAclResponse, err error) { - +func (c Client) SetACL(ctx context.Context, shareName string, input SetAclInput) (result SetAclResponse, err error) { if shareName == "" { - return resp, fmt.Errorf("`shareName` cannot be an empty string") + err = fmt.Errorf("`shareName` cannot be an empty string") + return } if strings.ToLower(shareName) != shareName { - return resp, fmt.Errorf("`shareName` must be a lower-cased string") + err = fmt.Errorf("`shareName` must be a lower-cased string") + return } opts := client.RequestOptions{ @@ -53,7 +54,8 @@ func (c Client) SetACL(ctx context.Context, shareName string, input SetAclInput) b, err := xml.Marshal(&input) if err != nil { - return resp, fmt.Errorf("marshalling input: %v", err) + err = fmt.Errorf("marshalling input: %+v", err) + return } withHeader := xml.Header + string(b) bytesWithHeader := []byte(withHeader) @@ -61,11 +63,16 @@ func (c Client) SetACL(ctx context.Context, shareName string, input SetAclInput) req.Header.Set("Content-Length", strconv.Itoa(len(bytesWithHeader))) req.Body = io.NopCloser(bytes.NewReader(bytesWithHeader)) - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return } + return } diff --git a/storage/2023-11-03/file/shares/create.go b/storage/2023-11-03/file/shares/create.go index b018460..fdf13e3 100644 --- a/storage/2023-11-03/file/shares/create.go +++ b/storage/2023-11-03/file/shares/create.go @@ -36,26 +36,30 @@ type CreateInput struct { } type CreateResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response } // Create creates the specified Storage Share within the specified Storage Account -func (c Client) Create(ctx context.Context, shareName string, input CreateInput) (resp CreateResponse, err error) { +func (c Client) Create(ctx context.Context, shareName string, input CreateInput) (result CreateResponse, err error) { if shareName == "" { - return resp, fmt.Errorf("`shareName` cannot be an empty string") + err = fmt.Errorf("`shareName` cannot be an empty string") + return } if strings.ToLower(shareName) != shareName { - return resp, fmt.Errorf("`shareName` must be a lower-cased string") + err = fmt.Errorf("`shareName` must be a lower-cased string") + return } if input.QuotaInGB <= 0 || input.QuotaInGB > 102400 { - return resp, fmt.Errorf("`input.QuotaInGB` must be greater than 0, and less than/equal to 100TB (102400 GB)") + err = fmt.Errorf("`input.QuotaInGB` must be greater than 0, and less than/equal to 100TB (102400 GB)") + return } if err = metadata.Validate(input.MetaData); err != nil { - return resp, fmt.Errorf("`input.MetaData` is not valid: %s", err) + err = fmt.Errorf("`input.MetaData` is not valid: %s", err) + return } opts := client.RequestOptions{ @@ -74,11 +78,17 @@ func (c Client) Create(ctx context.Context, shareName string, input CreateInput) err = fmt.Errorf("building request: %+v", err) return } - resp.HttpResponse, err = req.Execute(ctx) + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return } + return } diff --git a/storage/2023-11-03/file/shares/delete.go b/storage/2023-11-03/file/shares/delete.go index 7ae11b3..84667f6 100644 --- a/storage/2023-11-03/file/shares/delete.go +++ b/storage/2023-11-03/file/shares/delete.go @@ -11,7 +11,7 @@ import ( ) type DeleteResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response } type DeleteInput struct { @@ -19,13 +19,15 @@ type DeleteInput struct { } // Delete deletes the specified Storage Share from within a Storage Account -func (c Client) Delete(ctx context.Context, shareName string, input DeleteInput) (resp DeleteResponse, err error) { +func (c Client) Delete(ctx context.Context, shareName string, input DeleteInput) (result DeleteResponse, err error) { if shareName == "" { - return resp, fmt.Errorf("`shareName` cannot be an empty string") + err = fmt.Errorf("`shareName` cannot be an empty string") + return } if strings.ToLower(shareName) != shareName { - return resp, fmt.Errorf("`shareName` must be a lower-cased string") + err = fmt.Errorf("`shareName` must be a lower-cased string") + return } opts := client.RequestOptions{ @@ -45,7 +47,11 @@ func (c Client) Delete(ctx context.Context, shareName string, input DeleteInput) return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return diff --git a/storage/2023-11-03/file/shares/lifecycle_test.go b/storage/2023-11-03/file/shares/lifecycle_test.go index 29b6d19..b2e0637 100644 --- a/storage/2023-11-03/file/shares/lifecycle_test.go +++ b/storage/2023-11-03/file/shares/lifecycle_test.go @@ -89,7 +89,7 @@ func TestSharesLifecycle(t *testing.T) { t.Fatalf("Expected EnabledProtocol to SMB but got: %s", share.EnabledProtocol) } if share.AccessTier == nil || *share.AccessTier != CoolAccessTier { - t.Fatalf("Expected AccessTier to be Cool but got: %v", share.AccessTier) + t.Fatalf("Expected AccessTier to be Cool but got: %+v", share.AccessTier) } newTier := HotAccessTier @@ -112,7 +112,7 @@ func TestSharesLifecycle(t *testing.T) { } if share.AccessTier == nil || *share.AccessTier != HotAccessTier { - t.Fatalf("Expected AccessTier to be Hot but got: %v", share.AccessTier) + t.Fatalf("Expected AccessTier to be Hot but got: %+v", share.AccessTier) } updatedMetaData := map[string]string{ diff --git a/storage/2023-11-03/file/shares/metadata_get.go b/storage/2023-11-03/file/shares/metadata_get.go index e31762b..eeb8b4d 100644 --- a/storage/2023-11-03/file/shares/metadata_get.go +++ b/storage/2023-11-03/file/shares/metadata_get.go @@ -12,18 +12,18 @@ import ( ) type GetMetaDataResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response MetaData map[string]string } // GetMetaData returns the MetaData associated with the specified Storage Share -func (c Client) GetMetaData(ctx context.Context, shareName string) (resp GetMetaDataResponse, err error) { +func (c Client) GetMetaData(ctx context.Context, shareName string) (result GetMetaDataResponse, err error) { if shareName == "" { - return resp, fmt.Errorf("`shareName` cannot be an empty string") + return result, fmt.Errorf("`shareName` cannot be an empty string") } if strings.ToLower(shareName) != shareName { - return resp, fmt.Errorf("`shareName` must be a lower-cased string") + return result, fmt.Errorf("`shareName` must be a lower-cased string") } opts := client.RequestOptions{ @@ -42,18 +42,20 @@ func (c Client) GetMetaData(ctx context.Context, shareName string) (resp GetMeta return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + + if resp.Header != nil { + result.MetaData = metadata.ParseFromHeaders(resp.Header) + } + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return } - if resp.HttpResponse != nil { - if resp.HttpResponse.Header != nil { - resp.MetaData = metadata.ParseFromHeaders(resp.HttpResponse.Header) - } - } - return } diff --git a/storage/2023-11-03/file/shares/metadata_set.go b/storage/2023-11-03/file/shares/metadata_set.go index 3a23d90..55bf1d4 100644 --- a/storage/2023-11-03/file/shares/metadata_set.go +++ b/storage/2023-11-03/file/shares/metadata_set.go @@ -12,7 +12,7 @@ import ( ) type SetMetaDataResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response } type SetMetaDataInput struct { @@ -20,18 +20,21 @@ type SetMetaDataInput struct { } // SetMetaData sets the MetaData on the specified Storage Share -func (c Client) SetMetaData(ctx context.Context, shareName string, input SetMetaDataInput) (resp SetMetaDataResponse, err error) { +func (c Client) SetMetaData(ctx context.Context, shareName string, input SetMetaDataInput) (result SetMetaDataResponse, err error) { if shareName == "" { - return resp, fmt.Errorf("`shareName` cannot be an empty string") + err = fmt.Errorf("`shareName` cannot be an empty string") + return } if strings.ToLower(shareName) != shareName { - return resp, fmt.Errorf("`shareName` must be a lower-cased string") + err = fmt.Errorf("`shareName` must be a lower-cased string") + return } - if err := metadata.Validate(input.MetaData); err != nil { - return resp, fmt.Errorf("`metadata` is not valid: %v", err) + if err = metadata.Validate(input.MetaData); err != nil { + err = fmt.Errorf("`metadata` is not valid: %+v", err) + return } opts := client.RequestOptions{ @@ -52,7 +55,11 @@ func (c Client) SetMetaData(ctx context.Context, shareName string, input SetMeta return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return diff --git a/storage/2023-11-03/file/shares/properties_get.go b/storage/2023-11-03/file/shares/properties_get.go index 763584e..fb15362 100644 --- a/storage/2023-11-03/file/shares/properties_get.go +++ b/storage/2023-11-03/file/shares/properties_get.go @@ -12,7 +12,7 @@ import ( ) type GetPropertiesResult struct { - HttpResponse *client.Response + HttpResponse *http.Response MetaData map[string]string QuotaInGB int @@ -21,13 +21,15 @@ type GetPropertiesResult struct { } // GetProperties returns the properties about the specified Storage Share -func (c Client) GetProperties(ctx context.Context, shareName string) (resp GetPropertiesResult, err error) { +func (c Client) GetProperties(ctx context.Context, shareName string) (result GetPropertiesResult, err error) { if shareName == "" { - return resp, fmt.Errorf("`shareName` cannot be an empty string") + err = fmt.Errorf("`shareName` cannot be an empty string") + return } if strings.ToLower(shareName) != shareName { - return resp, fmt.Errorf("`shareName` must be a lower-cased string") + err = fmt.Errorf("`shareName` must be a lower-cased string") + return } opts := client.RequestOptions{ @@ -46,37 +48,40 @@ func (c Client) GetProperties(ctx context.Context, shareName string) (resp GetPr return } - resp.HttpResponse, err = req.Execute(ctx) - if err != nil { - err = fmt.Errorf("executing request: %+v", err) - return - } + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response - if resp.HttpResponse != nil { - if resp.HttpResponse.Header != nil { - resp.MetaData = metadata.ParseFromHeaders(resp.HttpResponse.Header) + if resp.Header != nil { + result.MetaData = metadata.ParseFromHeaders(resp.Header) - quotaRaw := resp.HttpResponse.Header.Get("x-ms-share-quota") + quotaRaw := resp.Header.Get("x-ms-share-quota") if quotaRaw != "" { quota, e := strconv.Atoi(quotaRaw) if e != nil { - return resp, fmt.Errorf("error converting %q to an integer: %s", quotaRaw, err) + err = fmt.Errorf("error converting %q to an integer: %s", quotaRaw, err) + return } - resp.QuotaInGB = quota + result.QuotaInGB = quota } protocol := SMB - if protocolRaw := resp.HttpResponse.Header.Get("x-ms-enabled-protocols"); protocolRaw != "" { + if protocolRaw := resp.Header.Get("x-ms-enabled-protocols"); protocolRaw != "" { protocol = ShareProtocol(protocolRaw) } - if accessTierRaw := resp.HttpResponse.Header.Get("x-ms-access-tier"); accessTierRaw != "" { + if accessTierRaw := resp.Header.Get("x-ms-access-tier"); accessTierRaw != "" { tier := AccessTier(accessTierRaw) - resp.AccessTier = &tier + result.AccessTier = &tier } - resp.EnabledProtocol = protocol + result.EnabledProtocol = protocol } } + if err != nil { + err = fmt.Errorf("executing request: %+v", err) + return + } return } diff --git a/storage/2023-11-03/file/shares/properties_set.go b/storage/2023-11-03/file/shares/properties_set.go index ef3854a..f80df4f 100644 --- a/storage/2023-11-03/file/shares/properties_set.go +++ b/storage/2023-11-03/file/shares/properties_set.go @@ -17,22 +17,22 @@ type ShareProperties struct { } type SetPropertiesResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response } // SetProperties lets you update the Quota for the specified Storage Share -func (c Client) SetProperties(ctx context.Context, shareName string, properties ShareProperties) (resp SetPropertiesResponse, err error) { +func (c Client) SetProperties(ctx context.Context, shareName string, properties ShareProperties) (result SetPropertiesResponse, err error) { if shareName == "" { - return resp, fmt.Errorf("`shareName` cannot be an empty string") + return result, fmt.Errorf("`shareName` cannot be an empty string") } if strings.ToLower(shareName) != shareName { - return resp, fmt.Errorf("`shareName` must be a lower-cased string") + return result, fmt.Errorf("`shareName` must be a lower-cased string") } if newQuotaGB := properties.QuotaInGb; newQuotaGB != nil && (*newQuotaGB <= 0 || *newQuotaGB > 102400) { - return resp, fmt.Errorf("`newQuotaGB` must be greater than 0, and less than/equal to 100TB (102400 GB)") + return result, fmt.Errorf("`newQuotaGB` must be greater than 0, and less than/equal to 100TB (102400 GB)") } opts := client.RequestOptions{ @@ -53,7 +53,11 @@ func (c Client) SetProperties(ctx context.Context, shareName string, properties return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return diff --git a/storage/2023-11-03/file/shares/snapshot_create.go b/storage/2023-11-03/file/shares/snapshot_create.go index 8ba7a07..d4dff03 100644 --- a/storage/2023-11-03/file/shares/snapshot_create.go +++ b/storage/2023-11-03/file/shares/snapshot_create.go @@ -16,7 +16,7 @@ type CreateSnapshotInput struct { } type CreateSnapshotResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response // This header is a DateTime value that uniquely identifies the share snapshot. // The value of this header may be used in subsequent requests to access the share snapshot. @@ -27,18 +27,21 @@ type CreateSnapshotResponse struct { // CreateSnapshot creates a read-only snapshot of the share // A share can support creation of 200 share snapshots. Attempting to create more than 200 share snapshots fails with 409 (Conflict). // Attempting to create a share snapshot while a previous Snapshot Share operation is in progress fails with 409 (Conflict). -func (c Client) CreateSnapshot(ctx context.Context, shareName string, input CreateSnapshotInput) (resp CreateSnapshotResponse, err error) { +func (c Client) CreateSnapshot(ctx context.Context, shareName string, input CreateSnapshotInput) (result CreateSnapshotResponse, err error) { if shareName == "" { - return resp, fmt.Errorf("`shareName` cannot be an empty string") + err = fmt.Errorf("`shareName` cannot be an empty string") + return } if strings.ToLower(shareName) != shareName { - return resp, fmt.Errorf("`shareName` must be a lower-cased string") + err = fmt.Errorf("`shareName` must be a lower-cased string") + return } if err = metadata.Validate(input.MetaData); err != nil { - return resp, fmt.Errorf("`input.MetaData` is not valid: %v", err) + err = fmt.Errorf("`input.MetaData` is not valid: %+v", err) + return } opts := client.RequestOptions{ @@ -59,17 +62,20 @@ func (c Client) CreateSnapshot(ctx context.Context, shareName string, input Crea return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + + if resp.Header != nil { + result.SnapshotDateTime = resp.Header.Get("x-ms-snapshot") + } + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return } - if resp.HttpResponse != nil { - if resp.HttpResponse.Header != nil { - resp.SnapshotDateTime = resp.HttpResponse.Header.Get("x-ms-snapshot") - } - } return } diff --git a/storage/2023-11-03/file/shares/snapshot_delete.go b/storage/2023-11-03/file/shares/snapshot_delete.go index bf3ccd6..64dd532 100644 --- a/storage/2023-11-03/file/shares/snapshot_delete.go +++ b/storage/2023-11-03/file/shares/snapshot_delete.go @@ -11,22 +11,22 @@ import ( ) type DeleteSnapshotResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response } // DeleteSnapshot deletes the specified Snapshot of a Storage Share -func (c Client) DeleteSnapshot(ctx context.Context, accountName, shareName string, shareSnapshot string) (resp DeleteSnapshotResponse, err error) { +func (c Client) DeleteSnapshot(ctx context.Context, accountName, shareName string, shareSnapshot string) (result DeleteSnapshotResponse, err error) { if shareName == "" { - return resp, fmt.Errorf("`shareName` cannot be an empty string") + return result, fmt.Errorf("`shareName` cannot be an empty string") } if strings.ToLower(shareName) != shareName { - return resp, fmt.Errorf("`shareName` must be a lower-cased string") + return result, fmt.Errorf("`shareName` must be a lower-cased string") } if shareSnapshot == "" { - return resp, fmt.Errorf("`shareSnapshot` cannot be an empty string") + return result, fmt.Errorf("`shareSnapshot` cannot be an empty string") } opts := client.RequestOptions{ @@ -47,7 +47,11 @@ func (c Client) DeleteSnapshot(ctx context.Context, accountName, shareName strin return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return diff --git a/storage/2023-11-03/file/shares/snapshot_get.go b/storage/2023-11-03/file/shares/snapshot_get.go index f4a12e9..e4aee48 100644 --- a/storage/2023-11-03/file/shares/snapshot_get.go +++ b/storage/2023-11-03/file/shares/snapshot_get.go @@ -12,7 +12,7 @@ import ( ) type GetSnapshotPropertiesResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response MetaData map[string]string } @@ -22,17 +22,20 @@ type GetSnapshotPropertiesInput struct { } // GetSnapshot gets information about the specified Snapshot of the specified Storage Share -func (c Client) GetSnapshot(ctx context.Context, shareName string, input GetSnapshotPropertiesInput) (resp GetSnapshotPropertiesResponse, err error) { +func (c Client) GetSnapshot(ctx context.Context, shareName string, input GetSnapshotPropertiesInput) (result GetSnapshotPropertiesResponse, err error) { if shareName == "" { - return resp, fmt.Errorf("`shareName` cannot be an empty string") + err = fmt.Errorf("`shareName` cannot be an empty string") + return } if strings.ToLower(shareName) != shareName { - return resp, fmt.Errorf("`shareName` must be a lower-cased string") + err = fmt.Errorf("`shareName` must be a lower-cased string") + return } if input.snapshotShare == "" { - return resp, fmt.Errorf("`snapshotShare` cannot be an empty string") + err = fmt.Errorf("`snapshotShare` cannot be an empty string") + return } opts := client.RequestOptions{ @@ -53,18 +56,20 @@ func (c Client) GetSnapshot(ctx context.Context, shareName string, input GetSnap return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + + if resp.Header != nil { + result.MetaData = metadata.ParseFromHeaders(resp.Header) + } + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return } - if resp.HttpResponse != nil { - if resp.HttpResponse.Header != nil { - resp.MetaData = metadata.ParseFromHeaders(resp.HttpResponse.Header) - } - } - return } diff --git a/storage/2023-11-03/file/shares/stats.go b/storage/2023-11-03/file/shares/stats.go index 23e48af..d375d83 100644 --- a/storage/2023-11-03/file/shares/stats.go +++ b/storage/2023-11-03/file/shares/stats.go @@ -11,7 +11,7 @@ import ( ) type GetStatsResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response // The approximate size of the data stored on the share. // Note that this value may not include all recently created or recently resized files. @@ -19,13 +19,15 @@ type GetStatsResponse struct { } // GetStats returns information about the specified Storage Share -func (c Client) GetStats(ctx context.Context, shareName string) (resp GetStatsResponse, err error) { +func (c Client) GetStats(ctx context.Context, shareName string) (result GetStatsResponse, err error) { if shareName == "" { - return resp, fmt.Errorf("`shareName` cannot be an empty string") + err = fmt.Errorf("`shareName` cannot be an empty string") + return } if strings.ToLower(shareName) != shareName { - return resp, fmt.Errorf("`shareName` must be a lower-cased string") + err = fmt.Errorf("`shareName` must be a lower-cased string") + return } opts := client.RequestOptions{ @@ -44,18 +46,22 @@ func (c Client) GetStats(ctx context.Context, shareName string) (resp GetStatsRe return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + + err = resp.Unmarshal(&result) + if err != nil { + err = fmt.Errorf("unmarshalling response: %+v", err) + return + } + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return } - if resp.HttpResponse != nil { - err = resp.HttpResponse.Unmarshal(&resp) - if err != nil { - return resp, fmt.Errorf("unmarshalling response: %v", err) - } - } return } diff --git a/storage/2023-11-03/queue/messages/delete.go b/storage/2023-11-03/queue/messages/delete.go index 870b3b7..cfec0a8 100644 --- a/storage/2023-11-03/queue/messages/delete.go +++ b/storage/2023-11-03/queue/messages/delete.go @@ -11,7 +11,7 @@ import ( ) type DeleteResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response } type DeleteInput struct { @@ -19,22 +19,22 @@ type DeleteInput struct { } // Delete deletes a specific message -func (c Client) Delete(ctx context.Context, queueName, messageID string, input DeleteInput) (resp DeleteResponse, err error) { +func (c Client) Delete(ctx context.Context, queueName, messageID string, input DeleteInput) (result DeleteResponse, err error) { if queueName == "" { - return resp, fmt.Errorf("`queueName` cannot be an empty string") + return result, fmt.Errorf("`queueName` cannot be an empty string") } if strings.ToLower(queueName) != queueName { - return resp, fmt.Errorf("`queueName` must be a lower-cased string") + return result, fmt.Errorf("`queueName` must be a lower-cased string") } if messageID == "" { - return resp, fmt.Errorf("`messageID` cannot be an empty string") + return result, fmt.Errorf("`messageID` cannot be an empty string") } if input.PopReceipt == "" { - return resp, fmt.Errorf("`input.PopReceipt` cannot be an empty string") + return result, fmt.Errorf("`input.PopReceipt` cannot be an empty string") } opts := client.RequestOptions{ @@ -55,7 +55,11 @@ func (c Client) Delete(ctx context.Context, queueName, messageID string, input D return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return diff --git a/storage/2023-11-03/queue/messages/get.go b/storage/2023-11-03/queue/messages/get.go index ff229bf..ae14dae 100644 --- a/storage/2023-11-03/queue/messages/get.go +++ b/storage/2023-11-03/queue/messages/get.go @@ -22,26 +22,22 @@ type GetInput struct { NumberOfMessages int } -type GetResponse struct { - HttpResponse *client.Response -} - // Get retrieves one or more messages from the front of the queue -func (c Client) Get(ctx context.Context, queueName string, input GetInput) (resp QueueMessagesListResponse, err error) { +func (c Client) Get(ctx context.Context, queueName string, input GetInput) (result QueueMessagesListResponse, err error) { if queueName == "" { - return resp, fmt.Errorf("`queueName` cannot be an empty string") + return result, fmt.Errorf("`queueName` cannot be an empty string") } if strings.ToLower(queueName) != queueName { - return resp, fmt.Errorf("`queueName` must be a lower-cased string") + return result, fmt.Errorf("`queueName` must be a lower-cased string") } if input.NumberOfMessages < 1 || input.NumberOfMessages > 32 { - return resp, fmt.Errorf("`input.NumberOfMessages` must be between 1 and 32") + return result, fmt.Errorf("`input.NumberOfMessages` must be between 1 and 32") } if input.VisibilityTimeout != nil { t := *input.VisibilityTimeout maxTime := (time.Hour * 24 * 7).Seconds() if t < 1 || t < int(maxTime) { - return resp, fmt.Errorf("`input.VisibilityTimeout` must be larger than or equal to 1 second, and cannot be larger than 7 days") + return result, fmt.Errorf("`input.VisibilityTimeout` must be larger than or equal to 1 second, and cannot be larger than 7 days") } } @@ -64,18 +60,22 @@ func (c Client) Get(ctx context.Context, queueName string, input GetInput) (resp return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + + err = resp.Unmarshal(&result) + if err != nil { + err = fmt.Errorf("unmarshalling response: %+v", err) + return + } + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return } - if resp.HttpResponse != nil { - if err = resp.HttpResponse.Unmarshal(&resp); err != nil { - return resp, fmt.Errorf("unmarshalling response: %+v", err) - } - } - return } diff --git a/storage/2023-11-03/queue/messages/models.go b/storage/2023-11-03/queue/messages/models.go index eb450f0..882df11 100644 --- a/storage/2023-11-03/queue/messages/models.go +++ b/storage/2023-11-03/queue/messages/models.go @@ -1,7 +1,7 @@ package messages import ( - "github.com/hashicorp/go-azure-sdk/sdk/client" + "net/http" ) type QueueMessage struct { @@ -9,7 +9,7 @@ type QueueMessage struct { } type QueueMessagesListResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response QueueMessages *[]QueueMessageResponse `xml:"QueueMessage"` } diff --git a/storage/2023-11-03/queue/messages/peek.go b/storage/2023-11-03/queue/messages/peek.go index c35157d..1b8886c 100644 --- a/storage/2023-11-03/queue/messages/peek.go +++ b/storage/2023-11-03/queue/messages/peek.go @@ -18,18 +18,18 @@ type PeekInput struct { } // Peek retrieves one or more messages from the front of the queue, but doesn't alter the visibility of the messages -func (c Client) Peek(ctx context.Context, queueName string, input PeekInput) (resp QueueMessagesListResponse, err error) { +func (c Client) Peek(ctx context.Context, queueName string, input PeekInput) (result QueueMessagesListResponse, err error) { if queueName == "" { - return resp, fmt.Errorf("`queueName` cannot be an empty string") + return result, fmt.Errorf("`queueName` cannot be an empty string") } if strings.ToLower(queueName) != queueName { - return resp, fmt.Errorf("`queueName` must be a lower-cased string") + return result, fmt.Errorf("`queueName` must be a lower-cased string") } if input.NumberOfMessages < 1 || input.NumberOfMessages > 32 { - return resp, fmt.Errorf("`input.NumberOfMessages` must be between 1 and 32") + return result, fmt.Errorf("`input.NumberOfMessages` must be between 1 and 32") } opts := client.RequestOptions{ @@ -50,18 +50,22 @@ func (c Client) Peek(ctx context.Context, queueName string, input PeekInput) (re return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + + err = resp.Unmarshal(&result) + if err != nil { + err = fmt.Errorf("unmarshalling response: %+v", err) + return + } + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return } - if resp.HttpResponse != nil { - if err = resp.HttpResponse.Unmarshal(&resp); err != nil { - return resp, fmt.Errorf("unmarshalling response: %+v", err) - } - } - return } diff --git a/storage/2023-11-03/queue/messages/put.go b/storage/2023-11-03/queue/messages/put.go index 19cde71..d59f844 100644 --- a/storage/2023-11-03/queue/messages/put.go +++ b/storage/2023-11-03/queue/messages/put.go @@ -33,13 +33,13 @@ type PutInput struct { } // Put adds a new message to the back of the message queue -func (c Client) Put(ctx context.Context, queueName string, input PutInput) (resp QueueMessagesListResponse, err error) { +func (c Client) Put(ctx context.Context, queueName string, input PutInput) (result QueueMessagesListResponse, err error) { if queueName == "" { - return resp, fmt.Errorf("`queueName` cannot be an empty string") + return result, fmt.Errorf("`queueName` cannot be an empty string") } if strings.ToLower(queueName) != queueName { - return resp, fmt.Errorf("`queueName` must be a lower-cased string") + return result, fmt.Errorf("`queueName` must be a lower-cased string") } opts := client.RequestOptions{ @@ -64,7 +64,7 @@ func (c Client) Put(ctx context.Context, queueName string, input PutInput) (resp MessageText: input.Message, }) if err != nil { - return resp, fmt.Errorf("marshalling request: %v", err) + return result, fmt.Errorf("marshalling request: %+v", err) } body := xml.Header + string(marshalledMsg) @@ -72,18 +72,22 @@ func (c Client) Put(ctx context.Context, queueName string, input PutInput) (resp req.ContentLength = int64(len(body)) req.Header.Set("Content-Length", strconv.Itoa(len(body))) - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + + err = resp.Unmarshal(&result) + if err != nil { + err = fmt.Errorf("unmarshalling response: %+v", err) + return + } + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return } - if resp.HttpResponse != nil { - if err = resp.HttpResponse.Unmarshal(&resp); err != nil { - return resp, fmt.Errorf("unmarshalling response: %+v", err) - } - } - return } diff --git a/storage/2023-11-03/queue/messages/update.go b/storage/2023-11-03/queue/messages/update.go index fa38011..15d266f 100644 --- a/storage/2023-11-03/queue/messages/update.go +++ b/storage/2023-11-03/queue/messages/update.go @@ -30,20 +30,20 @@ type UpdateInput struct { } type UpdateResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response } // Update updates an existing message based on it's Pop Receipt -func (c Client) Update(ctx context.Context, queueName string, messageID string, input UpdateInput) (resp UpdateResponse, err error) { +func (c Client) Update(ctx context.Context, queueName string, messageID string, input UpdateInput) (result UpdateResponse, err error) { if queueName == "" { - return resp, fmt.Errorf("`queueName` cannot be an empty string") + return result, fmt.Errorf("`queueName` cannot be an empty string") } if strings.ToLower(queueName) != queueName { - return resp, fmt.Errorf("`queueName` must be a lower-cased string") + return result, fmt.Errorf("`queueName` must be a lower-cased string") } if input.PopReceipt == "" { - return resp, fmt.Errorf("`input.PopReceipt` cannot be an empty string") + return result, fmt.Errorf("`input.PopReceipt` cannot be an empty string") } opts := client.RequestOptions{ @@ -68,7 +68,7 @@ func (c Client) Update(ctx context.Context, queueName string, messageID string, MessageText: input.Message, }) if err != nil { - return resp, fmt.Errorf("marshalling request: %v", err) + return result, fmt.Errorf("marshalling request: %+v", err) } body := xml.Header + string(marshalledMsg) @@ -76,7 +76,11 @@ func (c Client) Update(ctx context.Context, queueName string, messageID string, req.ContentLength = int64(len(body)) req.Header.Set("Content-Length", strconv.Itoa(len(body))) - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return diff --git a/storage/2023-11-03/queue/queues/create.go b/storage/2023-11-03/queue/queues/create.go index d156052..f548088 100644 --- a/storage/2023-11-03/queue/queues/create.go +++ b/storage/2023-11-03/queue/queues/create.go @@ -16,22 +16,22 @@ type CreateInput struct { } type CreateResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response } // Create creates the specified Queue within the specified Storage Account -func (c Client) Create(ctx context.Context, queueName string, input CreateInput) (resp CreateResponse, err error) { +func (c Client) Create(ctx context.Context, queueName string, input CreateInput) (result CreateResponse, err error) { if queueName == "" { - return resp, fmt.Errorf("`queueName` cannot be an empty string") + return result, fmt.Errorf("`queueName` cannot be an empty string") } if strings.ToLower(queueName) != queueName { - return resp, fmt.Errorf("`queueName` must be a lower-cased string") + return result, fmt.Errorf("`queueName` must be a lower-cased string") } if err := metadata.Validate(input.MetaData); err != nil { - return resp, fmt.Errorf("`metadata` is not valid: %s", err) + return result, fmt.Errorf("`metadata` is not valid: %s", err) } opts := client.RequestOptions{ @@ -52,7 +52,11 @@ func (c Client) Create(ctx context.Context, queueName string, input CreateInput) return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return diff --git a/storage/2023-11-03/queue/queues/delete.go b/storage/2023-11-03/queue/queues/delete.go index 39d5d64..e8d7bab 100644 --- a/storage/2023-11-03/queue/queues/delete.go +++ b/storage/2023-11-03/queue/queues/delete.go @@ -10,18 +10,18 @@ import ( ) type DeleteResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response } // Delete deletes the specified Queue within the specified Storage Account -func (c Client) Delete(ctx context.Context, queueName string) (resp DeleteResponse, err error) { +func (c Client) Delete(ctx context.Context, queueName string) (result DeleteResponse, err error) { if queueName == "" { - return resp, fmt.Errorf("`queueName` cannot be an empty string") + return result, fmt.Errorf("`queueName` cannot be an empty string") } if strings.ToLower(queueName) != queueName { - return resp, fmt.Errorf("`queueName` must be a lower-cased string") + return result, fmt.Errorf("`queueName` must be a lower-cased string") } opts := client.RequestOptions{ @@ -40,7 +40,11 @@ func (c Client) Delete(ctx context.Context, queueName string) (resp DeleteRespon return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return diff --git a/storage/2023-11-03/queue/queues/metadata_get.go b/storage/2023-11-03/queue/queues/metadata_get.go index 14c32d6..c8a259f 100644 --- a/storage/2023-11-03/queue/queues/metadata_get.go +++ b/storage/2023-11-03/queue/queues/metadata_get.go @@ -12,20 +12,20 @@ import ( ) type GetMetaDataResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response MetaData map[string]string } // GetMetaData returns the metadata for this Queue -func (c Client) GetMetaData(ctx context.Context, queueName string) (resp GetMetaDataResponse, err error) { +func (c Client) GetMetaData(ctx context.Context, queueName string) (result GetMetaDataResponse, err error) { if queueName == "" { - return resp, fmt.Errorf("`queueName` cannot be an empty string") + return result, fmt.Errorf("`queueName` cannot be an empty string") } if strings.ToLower(queueName) != queueName { - return resp, fmt.Errorf("`queueName` must be a lower-cased string") + return result, fmt.Errorf("`queueName` must be a lower-cased string") } opts := client.RequestOptions{ @@ -44,15 +44,23 @@ func (c Client) GetMetaData(ctx context.Context, queueName string) (resp GetMeta return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + + if resp.Header != nil { + result.MetaData = metadata.ParseFromHeaders(resp.Header) + } + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return } - if resp.HttpResponse != nil { - if resp.HttpResponse.Header != nil { - resp.MetaData = metadata.ParseFromHeaders(resp.HttpResponse.Header) + if result.HttpResponse != nil { + if result.HttpResponse.Header != nil { + result.MetaData = metadata.ParseFromHeaders(result.HttpResponse.Header) } } diff --git a/storage/2023-11-03/queue/queues/metadata_set.go b/storage/2023-11-03/queue/queues/metadata_set.go index ea8eac3..6ab770d 100644 --- a/storage/2023-11-03/queue/queues/metadata_set.go +++ b/storage/2023-11-03/queue/queues/metadata_set.go @@ -12,7 +12,7 @@ import ( ) type SetMetaDataResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response } type SetMetaDataInput struct { @@ -20,18 +20,18 @@ type SetMetaDataInput struct { } // SetMetaData returns the metadata for this Queue -func (c Client) SetMetaData(ctx context.Context, queueName string, input SetMetaDataInput) (resp SetMetaDataResponse, err error) { +func (c Client) SetMetaData(ctx context.Context, queueName string, input SetMetaDataInput) (result SetMetaDataResponse, err error) { if queueName == "" { - return resp, fmt.Errorf("`queueName` cannot be an empty string") + return result, fmt.Errorf("`queueName` cannot be an empty string") } if strings.ToLower(queueName) != queueName { - return resp, fmt.Errorf("`queueName` must be a lower-cased string") + return result, fmt.Errorf("`queueName` must be a lower-cased string") } if err := metadata.Validate(input.MetaData); err != nil { - return resp, fmt.Errorf("`metadata` is not valid: %v", err) + return result, fmt.Errorf("`metadata` is not valid: %+v", err) } opts := client.RequestOptions{ @@ -52,7 +52,11 @@ func (c Client) SetMetaData(ctx context.Context, queueName string, input SetMeta return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return diff --git a/storage/2023-11-03/queue/queues/models.go b/storage/2023-11-03/queue/queues/models.go index 2195244..fbbbce9 100644 --- a/storage/2023-11-03/queue/queues/models.go +++ b/storage/2023-11-03/queue/queues/models.go @@ -36,7 +36,7 @@ type Cors struct { type CorsRule struct { AllowedOrigins string `xml:"AllowedOrigins"` AllowedMethods string `xml:"AllowedMethods"` - AllowedHeaders string `xml:"AllowedHeaders` + AllowedHeaders string `xml:"AllowedHeaders"` ExposedHeaders string `xml:"ExposedHeaders"` MaxAgeInSeconds int `xml:"MaxAgeInSeconds"` } diff --git a/storage/2023-11-03/queue/queues/properties_get.go b/storage/2023-11-03/queue/queues/properties_get.go index b2ea774..0647f26 100644 --- a/storage/2023-11-03/queue/queues/properties_get.go +++ b/storage/2023-11-03/queue/queues/properties_get.go @@ -11,11 +11,11 @@ import ( type GetStorageServicePropertiesResponse struct { StorageServiceProperties - HttpResponse *client.Response + HttpResponse *http.Response } // GetServiceProperties gets the properties for this queue -func (c Client) GetServiceProperties(ctx context.Context) (resp GetStorageServicePropertiesResponse, err error) { +func (c Client) GetServiceProperties(ctx context.Context) (result GetStorageServicePropertiesResponse, err error) { opts := client.RequestOptions{ ContentType: "application/xml; charset=utf-8", @@ -33,18 +33,21 @@ func (c Client) GetServiceProperties(ctx context.Context) (resp GetStorageServic return } - resp.HttpResponse, err = req.Execute(ctx) - if err != nil { - err = fmt.Errorf("executing request: %+v", err) - return - } + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response - if resp.HttpResponse != nil { - err = resp.HttpResponse.Unmarshal(&resp) + err = resp.Unmarshal(&result) if err != nil { - return resp, fmt.Errorf("unmarshalling respnse: %v", err) + err = fmt.Errorf("unmarshalling response: %+v", err) + return } } + if err != nil { + err = fmt.Errorf("executing request: %+v", err) + return + } return } diff --git a/storage/2023-11-03/queue/queues/properties_set.go b/storage/2023-11-03/queue/queues/properties_set.go index 744bd97..d80b672 100644 --- a/storage/2023-11-03/queue/queues/properties_set.go +++ b/storage/2023-11-03/queue/queues/properties_set.go @@ -14,7 +14,7 @@ import ( ) type SetStorageServicePropertiesResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response } type SetStorageServicePropertiesInput struct { @@ -22,7 +22,7 @@ type SetStorageServicePropertiesInput struct { } // SetServiceProperties sets the properties for this queue -func (c Client) SetServiceProperties(ctx context.Context, input SetStorageServicePropertiesInput) (resp SetStorageServicePropertiesResponse, err error) { +func (c Client) SetServiceProperties(ctx context.Context, input SetStorageServicePropertiesInput) (result SetStorageServicePropertiesResponse, err error) { opts := client.RequestOptions{ ContentType: "application/xml; charset=utf-8", @@ -42,14 +42,18 @@ func (c Client) SetServiceProperties(ctx context.Context, input SetStorageServic marshalledProps, err := xml.Marshal(&input.Properties) if err != nil { - return resp, fmt.Errorf("marshalling request: %v", err) + return result, fmt.Errorf("marshalling request: %+v", err) } body := xml.Header + string(marshalledProps) req.Body = io.NopCloser(bytes.NewReader([]byte(body))) req.ContentLength = int64(len(body)) req.Header.Set("Content-Length", strconv.Itoa(len(body))) - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return diff --git a/storage/2023-11-03/table/entities/delete.go b/storage/2023-11-03/table/entities/delete.go index 05d09b3..61e7c71 100644 --- a/storage/2023-11-03/table/entities/delete.go +++ b/storage/2023-11-03/table/entities/delete.go @@ -20,22 +20,22 @@ type DeleteEntityInput struct { } type DeleteEntityResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response } // Delete deletes an existing entity in a table. -func (c Client) Delete(ctx context.Context, tableName string, input DeleteEntityInput) (resp DeleteEntityResponse, err error) { +func (c Client) Delete(ctx context.Context, tableName string, input DeleteEntityInput) (result DeleteEntityResponse, err error) { if tableName == "" { - return resp, fmt.Errorf("`tableName` cannot be an empty string") + return result, fmt.Errorf("`tableName` cannot be an empty string") } if input.PartitionKey == "" { - return resp, fmt.Errorf("`input.PartitionKey` cannot be an empty string") + return result, fmt.Errorf("`input.PartitionKey` cannot be an empty string") } if input.RowKey == "" { - return resp, fmt.Errorf("`input.RowKey` cannot be an empty string") + return result, fmt.Errorf("`input.RowKey` cannot be an empty string") } opts := client.RequestOptions{ @@ -54,7 +54,11 @@ func (c Client) Delete(ctx context.Context, tableName string, input DeleteEntity return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return diff --git a/storage/2023-11-03/table/entities/get.go b/storage/2023-11-03/table/entities/get.go index 14cd5ad..daf428a 100644 --- a/storage/2023-11-03/table/entities/get.go +++ b/storage/2023-11-03/table/entities/get.go @@ -18,23 +18,23 @@ type GetEntityInput struct { } type GetEntityResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response Entity map[string]interface{} } // Get queries entities in a table and includes the $filter and $select options. -func (c Client) Get(ctx context.Context, tableName string, input GetEntityInput) (resp GetEntityResponse, err error) { +func (c Client) Get(ctx context.Context, tableName string, input GetEntityInput) (result GetEntityResponse, err error) { if tableName == "" { - return resp, fmt.Errorf("`tableName` cannot be an empty string") + return result, fmt.Errorf("`tableName` cannot be an empty string") } if input.PartitionKey == "" { - return resp, fmt.Errorf("`input.PartitionKey` cannot be an empty string") + return result, fmt.Errorf("`input.PartitionKey` cannot be an empty string") } if input.RowKey == "" { - return resp, fmt.Errorf("`input.RowKey` cannot be an empty string") + return result, fmt.Errorf("`input.RowKey` cannot be an empty string") } opts := client.RequestOptions{ @@ -54,20 +54,22 @@ func (c Client) Get(ctx context.Context, tableName string, input GetEntityInput) return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + + err = resp.Unmarshal(&result.Entity) + if err != nil { + err = fmt.Errorf("unmarshalling response: %+v", err) + return + } + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return } - if resp.HttpResponse != nil { - if resp.HttpResponse.Body != nil { - err = resp.HttpResponse.Unmarshal(&resp.Entity) - if err != nil { - return resp, fmt.Errorf("unmarshalling response: %+v", err) - } - } - } return } diff --git a/storage/2023-11-03/table/entities/insert.go b/storage/2023-11-03/table/entities/insert.go index 315b7ce..1996ba8 100644 --- a/storage/2023-11-03/table/entities/insert.go +++ b/storage/2023-11-03/table/entities/insert.go @@ -28,21 +28,21 @@ type InsertEntityInput struct { } type InsertResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response } // Insert inserts a new entity into a table. -func (c Client) Insert(ctx context.Context, tableName string, input InsertEntityInput) (resp InsertResponse, err error) { +func (c Client) Insert(ctx context.Context, tableName string, input InsertEntityInput) (result InsertResponse, err error) { if tableName == "" { - return resp, fmt.Errorf("`tableName` cannot be an empty string") + return result, fmt.Errorf("`tableName` cannot be an empty string") } if input.PartitionKey == "" { - return resp, fmt.Errorf("`input.PartitionKey` cannot be an empty string") + return result, fmt.Errorf("`input.PartitionKey` cannot be an empty string") } if input.RowKey == "" { - return resp, fmt.Errorf("`input.RowKey` cannot be an empty string") + return result, fmt.Errorf("`input.RowKey` cannot be an empty string") } opts := client.RequestOptions{ @@ -68,10 +68,14 @@ func (c Client) Insert(ctx context.Context, tableName string, input InsertEntity err = req.Marshal(&input.Entity) if err != nil { - return resp, fmt.Errorf("marshalling request: %v", err) + return result, fmt.Errorf("marshalling request: %+v", err) } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return diff --git a/storage/2023-11-03/table/entities/insert_or_merge.go b/storage/2023-11-03/table/entities/insert_or_merge.go index 27cae93..8ec8191 100644 --- a/storage/2023-11-03/table/entities/insert_or_merge.go +++ b/storage/2023-11-03/table/entities/insert_or_merge.go @@ -25,22 +25,22 @@ type InsertOrMergeEntityInput struct { } type InsertOrMergeResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response } // InsertOrMerge updates an existing entity or inserts a new entity if it does not exist in the table. // Because this operation can insert or update an entity, it is also known as an upsert operation. -func (c Client) InsertOrMerge(ctx context.Context, tableName string, input InsertOrMergeEntityInput) (resp InsertOrMergeResponse, err error) { +func (c Client) InsertOrMerge(ctx context.Context, tableName string, input InsertOrMergeEntityInput) (result InsertOrMergeResponse, err error) { if tableName == "" { - return resp, fmt.Errorf("`tableName` cannot be an empty string") + return result, fmt.Errorf("`tableName` cannot be an empty string") } if input.PartitionKey == "" { - return resp, fmt.Errorf("`input.PartitionKey` cannot be an empty string") + return result, fmt.Errorf("`input.PartitionKey` cannot be an empty string") } if input.RowKey == "" { - return resp, fmt.Errorf("`input.RowKey` cannot be an empty string") + return result, fmt.Errorf("`input.RowKey` cannot be an empty string") } opts := client.RequestOptions{ @@ -64,10 +64,14 @@ func (c Client) InsertOrMerge(ctx context.Context, tableName string, input Inser err = req.Marshal(&input.Entity) if err != nil { - return resp, fmt.Errorf("marshalling request: %v", err) + return result, fmt.Errorf("marshalling request: %+v", err) } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return diff --git a/storage/2023-11-03/table/entities/insert_or_replace.go b/storage/2023-11-03/table/entities/insert_or_replace.go index 6f97eb6..269437c 100644 --- a/storage/2023-11-03/table/entities/insert_or_replace.go +++ b/storage/2023-11-03/table/entities/insert_or_replace.go @@ -25,22 +25,22 @@ type InsertOrReplaceEntityInput struct { } type InsertOrReplaceResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response } // InsertOrReplace replaces an existing entity or inserts a new entity if it does not exist in the table. // Because this operation can insert or update an entity, it is also known as an upsert operation. -func (c Client) InsertOrReplace(ctx context.Context, tableName string, input InsertOrReplaceEntityInput) (resp InsertOrReplaceResponse, err error) { +func (c Client) InsertOrReplace(ctx context.Context, tableName string, input InsertOrReplaceEntityInput) (result InsertOrReplaceResponse, err error) { if tableName == "" { - return resp, fmt.Errorf("`tableName` cannot be an empty string") + return result, fmt.Errorf("`tableName` cannot be an empty string") } if input.PartitionKey == "" { - return resp, fmt.Errorf("`input.PartitionKey` cannot be an empty string") + return result, fmt.Errorf("`input.PartitionKey` cannot be an empty string") } if input.RowKey == "" { - return resp, fmt.Errorf("`input.RowKey` cannot be an empty string") + return result, fmt.Errorf("`input.RowKey` cannot be an empty string") } opts := client.RequestOptions{ @@ -64,10 +64,14 @@ func (c Client) InsertOrReplace(ctx context.Context, tableName string, input Ins err = req.Marshal(&input.Entity) if err != nil { - return resp, fmt.Errorf("marshalling request: %v", err) + return result, fmt.Errorf("marshalling request: %+v", err) } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return diff --git a/storage/2023-11-03/table/entities/query.go b/storage/2023-11-03/table/entities/query.go index 9137401..57b411a 100644 --- a/storage/2023-11-03/table/entities/query.go +++ b/storage/2023-11-03/table/entities/query.go @@ -35,7 +35,7 @@ type QueryEntitiesInput struct { } type QueryEntitiesResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response NextPartitionKey string NextRowKey string @@ -45,9 +45,9 @@ type QueryEntitiesResponse struct { } // Query queries entities in a table and includes the $filter and $select options. -func (c Client) Query(ctx context.Context, tableName string, input QueryEntitiesInput) (resp QueryEntitiesResponse, err error) { +func (c Client) Query(ctx context.Context, tableName string, input QueryEntitiesInput) (result QueryEntitiesResponse, err error) { if tableName == "" { - return resp, fmt.Errorf("`tableName` cannot be an empty string") + return result, fmt.Errorf("`tableName` cannot be an empty string") } additionalParameters := make([]string, 0) @@ -82,21 +82,22 @@ func (c Client) Query(ctx context.Context, tableName string, input QueryEntities return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + + err = resp.Unmarshal(&result) + if err != nil { + err = fmt.Errorf("unmarshalling response: %+v", err) + return + } + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return } - if resp.HttpResponse != nil { - if resp.HttpResponse.Body != nil { - err = resp.HttpResponse.Unmarshal(&resp) - if err != nil { - return resp, fmt.Errorf("unmarshalling response: %v", err) - } - } - } - return } diff --git a/storage/2023-11-03/table/tables/acl_get.go b/storage/2023-11-03/table/tables/acl_get.go index d927d38..3f2f2a1 100644 --- a/storage/2023-11-03/table/tables/acl_get.go +++ b/storage/2023-11-03/table/tables/acl_get.go @@ -10,16 +10,17 @@ import ( ) type GetACLResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response SignedIdentifiers []SignedIdentifier `xml:"SignedIdentifier"` } // GetACL returns the Access Control List for the specified Table -func (c Client) GetACL(ctx context.Context, tableName string) (resp GetACLResponse, err error) { +func (c Client) GetACL(ctx context.Context, tableName string) (result GetACLResponse, err error) { if tableName == "" { - return resp, fmt.Errorf("`tableName` cannot be an empty string") + err = fmt.Errorf("`tableName` cannot be an empty string") + return } opts := client.RequestOptions{ @@ -38,21 +39,22 @@ func (c Client) GetACL(ctx context.Context, tableName string) (resp GetACLRespon return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + + err = resp.Unmarshal(&result) + if err != nil { + err = fmt.Errorf("unmarshalling response: %+v", err) + return + } + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return } - if resp.HttpResponse != nil { - if resp.HttpResponse.Body != nil { - err = resp.HttpResponse.Unmarshal(&resp) - if err != nil { - return resp, fmt.Errorf("unmarshalling response body: %v", err) - } - } - } - return } diff --git a/storage/2023-11-03/table/tables/acl_set.go b/storage/2023-11-03/table/tables/acl_set.go index 9ff4ad0..9749bd0 100644 --- a/storage/2023-11-03/table/tables/acl_set.go +++ b/storage/2023-11-03/table/tables/acl_set.go @@ -17,13 +17,14 @@ type setAcl struct { } type SetACLResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response } // SetACL sets the specified Access Control List for the specified Table -func (c Client) SetACL(ctx context.Context, tableName string, acls []SignedIdentifier) (resp SetACLResponse, err error) { +func (c Client) SetACL(ctx context.Context, tableName string, acls []SignedIdentifier) (result SetACLResponse, err error) { if tableName == "" { - return resp, fmt.Errorf("`tableName` cannot be an empty string") + err = fmt.Errorf("`tableName` cannot be an empty string") + return } opts := client.RequestOptions{ @@ -44,10 +45,15 @@ func (c Client) SetACL(ctx context.Context, tableName string, acls []SignedIdent err = req.Marshal(setAcl{SignedIdentifiers: acls}) if err != nil { - return resp, fmt.Errorf("marshalling request: %+v", err) + err = fmt.Errorf("marshalling request: %+v", err) + return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return diff --git a/storage/2023-11-03/table/tables/create.go b/storage/2023-11-03/table/tables/create.go index feeebe4..6adfd5a 100644 --- a/storage/2023-11-03/table/tables/create.go +++ b/storage/2023-11-03/table/tables/create.go @@ -14,13 +14,14 @@ type createTableRequest struct { } type CreateTableResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response } // Create creates a new table in the storage account. -func (c Client) Create(ctx context.Context, tableName string) (resp CreateTableResponse, err error) { +func (c Client) Create(ctx context.Context, tableName string) (result CreateTableResponse, err error) { if tableName == "" { - return resp, fmt.Errorf("`tableName` cannot be an empty string") + err = fmt.Errorf("`tableName` cannot be an empty string") + return } opts := client.RequestOptions{ @@ -41,10 +42,14 @@ func (c Client) Create(ctx context.Context, tableName string) (resp CreateTableR err = req.Marshal(&createTableRequest{TableName: tableName}) if err != nil { - return resp, fmt.Errorf("marshalling request") + return result, fmt.Errorf("marshalling request") } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return diff --git a/storage/2023-11-03/table/tables/delete.go b/storage/2023-11-03/table/tables/delete.go index 3a2817f..b1fab65 100644 --- a/storage/2023-11-03/table/tables/delete.go +++ b/storage/2023-11-03/table/tables/delete.go @@ -10,13 +10,14 @@ import ( ) type DeleteTableResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response } // Delete deletes the specified table and any data it contains. -func (c Client) Delete(ctx context.Context, tableName string) (resp DeleteTableResponse, err error) { +func (c Client) Delete(ctx context.Context, tableName string) (result DeleteTableResponse, err error) { if tableName == "" { - return resp, fmt.Errorf("`tableName` cannot be an empty string") + err = fmt.Errorf("`tableName` cannot be an empty string") + return } opts := client.RequestOptions{ @@ -35,7 +36,11 @@ func (c Client) Delete(ctx context.Context, tableName string) (resp DeleteTableR return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return diff --git a/storage/2023-11-03/table/tables/exists.go b/storage/2023-11-03/table/tables/exists.go index 1497695..efd922e 100644 --- a/storage/2023-11-03/table/tables/exists.go +++ b/storage/2023-11-03/table/tables/exists.go @@ -10,13 +10,14 @@ import ( ) type TableExistsResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response } // Exists checks that the specified table exists -func (c Client) Exists(ctx context.Context, tableName string) (resp TableExistsResponse, err error) { +func (c Client) Exists(ctx context.Context, tableName string) (result TableExistsResponse, err error) { if tableName == "" { - return resp, fmt.Errorf("`tableName` cannot be an empty string") + err = fmt.Errorf("`tableName` cannot be an empty string") + return } opts := client.RequestOptions{ @@ -37,10 +38,15 @@ func (c Client) Exists(ctx context.Context, tableName string) (resp TableExistsR err = req.Marshal(&createTableRequest{TableName: tableName}) if err != nil { - return resp, fmt.Errorf("marshalling request") + err = fmt.Errorf("marshalling request") + return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return diff --git a/storage/2023-11-03/table/tables/query.go b/storage/2023-11-03/table/tables/query.go index 9a15de8..4cc07ea 100644 --- a/storage/2023-11-03/table/tables/query.go +++ b/storage/2023-11-03/table/tables/query.go @@ -10,7 +10,7 @@ import ( ) type GetResponse struct { - HttpResponse *client.Response + HttpResponse *http.Response MetaData string `json:"odata.metadata,omitempty"` Tables []GetResultItem `json:"value"` @@ -21,7 +21,7 @@ type QueryInput struct { } // Query returns a list of tables under the specified account. -func (c Client) Query(ctx context.Context, input QueryInput) (resp GetResponse, err error) { +func (c Client) Query(ctx context.Context, input QueryInput) (result GetResponse, err error) { opts := client.RequestOptions{ ExpectedStatusCodes: []int{ @@ -40,21 +40,22 @@ func (c Client) Query(ctx context.Context, input QueryInput) (resp GetResponse, return } - resp.HttpResponse, err = req.Execute(ctx) + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.HttpResponse = resp.Response + + err = resp.Unmarshal(&result) + if err != nil { + err = fmt.Errorf("unmarshalling response: %+v", err) + return + } + } if err != nil { err = fmt.Errorf("executing request: %+v", err) return } - if resp.HttpResponse != nil { - if resp.HttpResponse.Body != nil { - err = resp.HttpResponse.Unmarshal(&resp) - if err != nil { - return resp, fmt.Errorf("unmarshalling response: %v", err) - } - } - } - return } diff --git a/storage/internal/metadata/parse.go b/storage/internal/metadata/parse.go index 038b12c..5f613ab 100644 --- a/storage/internal/metadata/parse.go +++ b/storage/internal/metadata/parse.go @@ -5,7 +5,7 @@ import ( "strings" ) -// ParseFromHeaders parses the meta data from the headers +// ParseFromHeaders parses the metadata from the headers func ParseFromHeaders(headers http.Header) map[string]string { metaData := make(map[string]string, 0) prefix := "x-ms-meta-"