Skip to content

Commit ec0238f

Browse files
Edits
1 parent 6845aa5 commit ec0238f

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

articles/storage/blobs/storage-blob-client-management.md

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -321,12 +321,31 @@ def get_blob_container_client(self, account_name, container_name):
321321
322322
## [Go](#tab/go)
323323
324+
Add the following `import` statements:
325+
324326
```go
325-
func getBlobContainerClient(accountName string, containerName string) *azblob.ContainerClient {
326-
// Append the container name to the end of the URI
327-
containerURL := fmt.Printf("https://%s.blob.core.windows.net/%s", accountName, containerName)
328-
containerClient := azblob.NewClient(containerURL, nil)
329-
return containerClient
327+
import (
328+
"context"
329+
"fmt"
330+
331+
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
332+
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/container"
333+
)
334+
```
335+
336+
Add the following code to create the client object:
337+
338+
```go
339+
func getBlobContainerClient(accountName string, containerName string) *container.Client {
340+
// Create a new container client with token credential
341+
credential, err := azidentity.NewDefaultAzureCredential(nil)
342+
handleError(err)
343+
344+
containerURL := fmt.Sprintf("https://%s.blob.core.windows.net/%s", accountName, containerName)
345+
containerClient, err := container.NewClient(containerURL, credential, nil)
346+
handleError(err)
347+
348+
return containerClient
330349
}
331350
```
332351
@@ -386,10 +405,8 @@ def get_blob_client(self, blob_service_client: BlobServiceClient, container_name
386405
387406
```go
388407
func getBlobClient(client *azblob.Client, containerName string, blobName string) *azblob.BlobClient {
389-
// Create the container client using the azblob client object
390-
blobClient := client.ServiceClient()
391-
.NewContainerClient(containerName)
392-
.NewBlobClient(blobName)
408+
// Create the blob client using the azblob client object
409+
blobClient := client.ServiceClient().NewContainerClient(containerName).NewBlobClient(blobName)
393410
return blobClient
394411
}
395412
```

0 commit comments

Comments
 (0)