Skip to content

Commit 66564c3

Browse files
Edits
1 parent 1ef24c9 commit 66564c3

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

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

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,39 @@ def get_blob_service_client(self, account_name):
156156
return blob_service_client
157157
```
158158

159+
## [Go](#tab/go)
160+
161+
Add the following `import` statements:
162+
163+
```go
164+
import (
165+
"context"
166+
"fmt"
167+
168+
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
169+
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
170+
)
171+
```
172+
173+
Add the following code to create the client object:
174+
175+
```go
176+
func getClient(accountName string) *azblob.Client {
177+
accountURL := fmt.Printf("https://%s.blob.core.windows.net", accountName)
178+
179+
// Create a new service client with token credential
180+
credential, err := azidentity.NewDefaultAzureCredential(nil)
181+
handleError(err)
182+
183+
client, err := azblob.NewClient(accountURL, credential, nil)
184+
handleError(err)
185+
186+
return client
187+
}
188+
```
189+
190+
Instances of `azblob.Client` provide methods for manipulating blob containers and blobs within a storage account. The storage account endpoint is specified when constructing the client object.
191+
159192
---
160193

161194
### Create a BlobContainerClient object
@@ -204,6 +237,18 @@ def get_blob_container_client(self, blob_service_client: BlobServiceClient, cont
204237
return container_client
205238
```
206239

240+
## [Go](#tab/go)
241+
242+
```go
243+
func getBlobContainerClient(client *azblob.Client, containerName string) *azblob.ContainerClient {
244+
// Create the container client using the azblob client object
245+
containerClient := client.ServiceClient().NewContainerClient(containerName)
246+
return containerClient
247+
}
248+
```
249+
250+
Instances of `azblob.Client` provide methods for working with blob containers and blobs within a storage account. For most operations, you can use the `azblob.Client` instance rather than creating a separate `ContainerClient` instance.
251+
207252
---
208253

209254
If your work is narrowly scoped to a single container, you might choose to create a `BlobContainerClient` object directly without using `BlobServiceClient`. You can still set client options on a container client just like you would on a service client.
@@ -273,6 +318,17 @@ def get_blob_container_client(self, account_name, container_name):
273318
return container_client
274319
```
275320
321+
## [Go](#tab/go)
322+
323+
```go
324+
func getBlobContainerClient(accountName string, containerName string) *azblob.ContainerClient {
325+
// Append the container name to the end of the URI
326+
containerURL := fmt.Printf("https://%s.blob.core.windows.net/%s", accountName, containerName)
327+
containerClient := azblob.NewClient(containerURL, nil)
328+
return containerClient
329+
}
330+
```
331+
276332
---
277333
278334
### Create a BlobClient object
@@ -325,6 +381,18 @@ def get_blob_client(self, blob_service_client: BlobServiceClient, container_name
325381
return blob_client
326382
```
327383
384+
## [Go](#tab/go)
385+
386+
```go
387+
func getBlobClient(client *azblob.Client, containerName string, blobName string) *azblob.BlobClient {
388+
// Create the container client using the azblob client object
389+
blobClient := client.ServiceClient().NewContainerClient(containerName).NewBlobClient(blobName)
390+
return blobClient
391+
}
392+
```
393+
394+
Instances of `azblob.Client` provide methods for working with blob containers and blobs within a storage account. For most operations, you can use the `azblob.Client` instance rather than creating a separate `BlobClient` instance.
395+
328396
---
329397
330398
## Manage client objects

0 commit comments

Comments
 (0)