Skip to content

Commit daa653c

Browse files
authored
Merge pull request #273864 from pauljewellmsft/devguide-go
Add blob developer guide content for Go
2 parents 612a180 + bd23251 commit daa653c

27 files changed

+1162
-22
lines changed

articles/storage/blobs/TOC.yml

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ items:
559559
href: storage-blob-dotnet-get-started.md
560560
- name: Authorize access from your application
561561
items:
562-
- name: Azure Active Directory
562+
- name: Microsoft Entra ID
563563
items:
564564
- name: Overview
565565
href: /dotnet/azure/sdk/authentication?toc=/azure/storage/blobs/toc.json&bc=/azure/storage/blobs/breadcrumb/toc.json
@@ -653,7 +653,7 @@ items:
653653
href: storage-blob-java-get-started.md
654654
- name: Authorize access from your application
655655
items:
656-
- name: Azure Active Directory
656+
- name: Microsoft Entra ID
657657
items:
658658
- name: Overview
659659
href: /azure/developer/java/sdk/identity?toc=/azure/storage/blobs/toc.json&bc=/azure/storage/blobs/breadcrumb/toc.json
@@ -733,7 +733,7 @@ items:
733733
href: storage-blob-javascript-get-started.md
734734
- name: Authorize access from your application
735735
items:
736-
- name: Azure Active Directory
736+
- name: Microsoft Entra ID
737737
items:
738738
- name: Overview
739739
href: /azure/developer/javascript/sdk/authentication/overview?toc=/azure/storage/blobs/toc.json&bc=/azure/storage/blobs/breadcrumb/toc.json
@@ -803,7 +803,7 @@ items:
803803
href: storage-blob-typescript-get-started.md
804804
- name: Authorize access from your application
805805
items:
806-
- name: Azure Active Directory
806+
- name: Microsoft Entra ID
807807
items:
808808
- name: Overview
809809
href: /azure/developer/javascript/sdk/authentication/overview?toc=/azure/storage/blobs/toc.json&bc=/azure/storage/blobs/breadcrumb/toc.json
@@ -871,7 +871,7 @@ items:
871871
href: storage-blob-python-get-started.md
872872
- name: Authorize access from your application
873873
items:
874-
- name: Azure Active Directory
874+
- name: Microsoft Entra ID
875875
items:
876876
- name: Overview
877877
href: /azure/developer/python/sdk/authentication-overview?toc=/azure/storage/blobs/toc.json&bc=/azure/storage/blobs/breadcrumb/toc.json
@@ -945,6 +945,42 @@ items:
945945
href: storage-retry-policy-python.md
946946
- name: Configure logging
947947
href: /azure/developer/python/sdk/azure-sdk-logging?toc=/azure/storage/blobs/toc.json&bc=/azure/storage/blobs/breadcrumb/toc.json
948+
- name: Go
949+
items:
950+
- name: Get started
951+
href: storage-blob-go-get-started.md
952+
- name: Authorize access from your application
953+
items:
954+
- name: Microsoft Entra ID
955+
items:
956+
- name: Authentication in development environments
957+
href: /azure/developer/go/azure-sdk-authentication?toc=/azure/storage/blobs/toc.json&bc=/azure/storage/blobs/breadcrumb/toc.json
958+
- name: Authentication in Azure-hosted apps
959+
href: /azure/developer/go/azure-sdk-authentication-managed-identity?toc=/azure/storage/blobs/toc.json&bc=/azure/storage/blobs/breadcrumb/toc.json
960+
- name: Authentication with a service principal
961+
href: /azure/developer/go/azure-sdk-authentication-service-principal?toc=/azure/storage/blobs/toc.json&bc=/azure/storage/blobs/breadcrumb/toc.json
962+
- name: Container actions
963+
items:
964+
- name: Create a container
965+
href: storage-blob-container-create-go.md
966+
- name: Delete and restore containers
967+
href: storage-blob-container-delete-go.md
968+
- name: List containers
969+
href: storage-blob-containers-list-go.md
970+
- name: Manage properties and metadata
971+
href: storage-blob-container-properties-metadata-go.md
972+
- name: Blob actions
973+
items:
974+
- name: Upload blobs
975+
href: storage-blob-upload-go.md
976+
- name: Download blobs
977+
href: storage-blob-download-go.md
978+
- name: List blobs
979+
href: storage-blobs-list-go.md
980+
- name: Delete and restore blobs
981+
href: storage-blob-delete-go.md
982+
- name: Manage blob properties and metadata
983+
href: storage-blob-properties-metadata-go.md
948984
- name: Test with a storage emulator
949985
items:
950986
- name: Use the Azurite open-source emulator

articles/storage/blobs/breadcrumb/toc.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,7 @@
2323
topicHref: /azure/storage/blobs/storage-blobs-introduction
2424
- name: Blobs
2525
tocHref: /azure/developer/java/sdk/
26+
topicHref: /azure/storage/blobs/storage-blobs-introduction
27+
- name: Blobs
28+
tocHref: /azure/developer/go/
2629
topicHref: /azure/storage/blobs/storage-blobs-introduction
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
---
2+
title: Create a blob container with Go
3+
titleSuffix: Azure Storage
4+
description: Learn how to create a blob container in your Azure Storage account using the Go client library.
5+
services: storage
6+
author: pauljewellmsft
7+
8+
ms.service: azure-blob-storage
9+
ms.topic: how-to
10+
ms.date: 05/22/2024
11+
ms.author: pauljewell
12+
ms.devlang: golang
13+
ms.custom: devx-track-go, devguide-go
14+
---
15+
16+
# Create a blob container with Go
17+
18+
[!INCLUDE [storage-dev-guide-selector-create-container](../../../includes/storage-dev-guides/storage-dev-guide-selector-create-container.md)]
19+
20+
This article shows how to create containers with the [Azure Storage client module for Go](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/storage/azblob#section-readme). Blobs in Azure Storage are organized into containers. Before you can upload a blob, you must first create a container.
21+
22+
[!INCLUDE [storage-dev-guide-prereqs-go](../../../includes/storage-dev-guides/storage-dev-guide-prereqs-go.md)]
23+
24+
## Set up your environment
25+
26+
[!INCLUDE [storage-dev-guide-project-setup-go](../../../includes/storage-dev-guides/storage-dev-guide-project-setup-go.md)]
27+
28+
#### Authorization
29+
30+
The authorization mechanism must have the necessary permissions to create a container. For authorization with Microsoft Entra ID (recommended), you need Azure RBAC built-in role **Storage Blob Data Contributor** or higher. To learn more, see the authorization guidance for [Create Container (REST API)](/rest/api/storageservices/create-container#authorization).
31+
32+
[!INCLUDE [storage-dev-guide-about-container-naming](../../../includes/storage-dev-guides/storage-dev-guide-about-container-naming.md)]
33+
34+
## Create a container
35+
36+
To create a container, call the following method:
37+
38+
- [CreateContainer](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/storage/azblob#Client.CreateContainer)
39+
40+
Containers are created immediately beneath the storage account. It's not possible to nest one container beneath another. An exception is thrown if a container with the same name already exists.
41+
42+
The following example shows how to create a container:
43+
44+
:::code language="go" source="~/blob-devguide-go/cmd/create-container/create_container.go" id="snippet_create_container":::
45+
46+
## Create the root container
47+
48+
A root container serves as a default container for your storage account. Each storage account can have one root container, which must be named *$root*. The root container must be explicitly created or deleted.
49+
50+
You can reference a blob stored in the root container without including the root container name. The root container enables you to reference a blob at the top level of the storage account hierarchy. For example, you can reference a blob in the root container as follows:
51+
52+
`https://<storage-account-name>.blob.core.windows.net/default.html`
53+
54+
The following example creates the container if it doesn't already exist in the storage account:
55+
56+
:::code language="go" source="~/blob-devguide-go/cmd/create-container/create_container.go" id="snippet_create_root_container":::
57+
58+
[!INCLUDE [storage-dev-guide-code-samples-note-go](../../../includes/storage-dev-guides/storage-dev-guide-code-samples-note-go.md)]
59+
60+
## Resources
61+
62+
To learn more about creating a container using the Azure Blob Storage client module for Go, see the following resources.
63+
64+
### Code samples
65+
66+
- View [code samples](https://github.com/Azure-Samples/blob-storage-devguide-go/blob/main/cmd/create-container/create_container.go) from this article (GitHub)
67+
68+
### REST API operations
69+
70+
The Azure SDK for Go contains libraries that build on top of the Azure REST API, allowing you to interact with REST API operations through familiar Go paradigms. The client library methods for creating a container use the following REST API operation:
71+
72+
- [Create Container](/rest/api/storageservices/create-container) (REST API)
73+
74+
[!INCLUDE [storage-dev-guide-resources-go](../../../includes/storage-dev-guides/storage-dev-guide-resources-go.md)]
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
---
2+
title: Delete and restore a blob container with Go
3+
titleSuffix: Azure Storage
4+
description: Learn how to delete and restore a blob container in your Azure Storage account using the Go client library.
5+
services: storage
6+
author: pauljewellmsft
7+
8+
ms.service: azure-blob-storage
9+
ms.topic: how-to
10+
ms.date: 05/22/2024
11+
ms.author: pauljewell
12+
ms.devlang: golang
13+
ms.custom: devx-track-go, devguide-go
14+
---
15+
16+
# Delete and restore a blob container with Go
17+
18+
[!INCLUDE [storage-dev-guide-selector-delete-container](../../../includes/storage-dev-guides/storage-dev-guide-selector-delete-container.md)]
19+
20+
This article shows how to delete containers with the [Azure Storage client module for Go](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/storage/azblob#section-readme). If you've enabled [container soft delete](soft-delete-container-overview.md), you can restore deleted containers.
21+
22+
[!INCLUDE [storage-dev-guide-prereqs-go](../../../includes/storage-dev-guides/storage-dev-guide-prereqs-go.md)]
23+
24+
## Set up your environment
25+
26+
[!INCLUDE [storage-dev-guide-project-setup-go](../../../includes/storage-dev-guides/storage-dev-guide-project-setup-go.md)]
27+
28+
#### Authorization
29+
30+
The authorization mechanism must have the necessary permissions to delete or restore a container. For authorization with Microsoft Entra ID (recommended), you need Azure RBAC built-in role **Storage Blob Data Contributor** or higher. To learn more, see the authorization guidance for [Delete Container (REST API)](/rest/api/storageservices/delete-container#authorization) and [Restore Container (REST API)](/rest/api/storageservices/restore-container#authorization).
31+
32+
## Delete a container
33+
34+
To delete a container, call the following method:
35+
36+
- [DeleteContainer](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/storage/azblob#Client.DeleteContainer)
37+
38+
After you delete a container, you can't create a container with the same name for *at least* 30 seconds. Attempting to create a container with the same name fails with HTTP error code `409 (Conflict)`. Any other operations on the container or the blobs it contains fail with HTTP error code `404 (Not Found)`.
39+
40+
The following example shows how to delete a specified container:
41+
42+
:::code language="go" source="~/blob-devguide-go/cmd/delete-container/delete_container.go" id="snippet_delete_container":::
43+
44+
## Restore a deleted container
45+
46+
When container soft delete is enabled for a storage account, a deleted container and its contents can be recovered within a specified retention period. To learn more about container soft delete, see [Enable and manage soft delete for containers](soft-delete-container-enable.md). You can restore a soft-deleted container by calling the following method from the embedded [ServiceClient](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/storage/azblob#Client.ServiceClient) for the client object:
47+
48+
- [RestoreContainer](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/service#Client.RestoreContainer)
49+
50+
The following example lists containers, including soft-deleted containers, and iterates over the list to restore the specified soft-deleted container:
51+
52+
:::code language="go" source="~/blob-devguide-go/cmd/delete-container/delete_container.go" id="snippet_restore_container":::
53+
54+
[!INCLUDE [storage-dev-guide-code-samples-note-go](../../../includes/storage-dev-guides/storage-dev-guide-code-samples-note-go.md)]
55+
56+
## Resources
57+
58+
To learn more about deleting a container using the Azure Blob Storage client module for Go, see the following resources.
59+
60+
### Code samples
61+
62+
- View [code samples](https://github.com/Azure-Samples/blob-storage-devguide-go/blob/main/cmd/delete-container/delete_container.go) from this article (GitHub)
63+
64+
### REST API operations
65+
66+
The Azure SDK for Go contains libraries that build on top of the Azure REST API, allowing you to interact with REST API operations through familiar Go paradigms. The client library methods for deleting or restoring a container use the following REST API operations:
67+
68+
- [Delete Container](/rest/api/storageservices/delete-container) (REST API)
69+
- [Restore Container](/rest/api/storageservices/restore-container) (REST API)
70+
71+
[!INCLUDE [storage-dev-guide-resources-go](../../../includes/storage-dev-guides/storage-dev-guide-resources-go.md)]
72+
73+
### See also
74+
75+
- [Soft delete for containers](soft-delete-container-overview.md)
76+
- [Enable and manage soft delete for containers](soft-delete-container-enable.md)
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
---
2+
title: Use Go to manage properties and metadata for a blob container
3+
titleSuffix: Azure Storage
4+
description: Learn how to set and retrieve system properties and store custom metadata on blob containers in your Azure Storage account using the Go client library.
5+
services: storage
6+
author: pauljewellmsft
7+
8+
ms.service: azure-blob-storage
9+
ms.topic: how-to
10+
ms.date: 05/22/2024
11+
ms.author: pauljewell
12+
ms.devlang: golang
13+
ms.custom: devx-track-go, devguide-go
14+
---
15+
16+
# Manage container properties and metadata with Go
17+
18+
[!INCLUDE [storage-dev-guide-selector-manage-properties-container](../../../includes/storage-dev-guides/storage-dev-guide-selector-manage-properties-container.md)]
19+
20+
Blob containers support system properties and user-defined metadata, in addition to the data they contain. This article shows how to manage system properties and user-defined metadata with the [Azure Storage client module for Go](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/storage/azblob#section-readme).
21+
22+
[!INCLUDE [storage-dev-guide-prereqs-go](../../../includes/storage-dev-guides/storage-dev-guide-prereqs-go.md)]
23+
24+
## Set up your environment
25+
26+
[!INCLUDE [storage-dev-guide-project-setup-go](../../../includes/storage-dev-guides/storage-dev-guide-project-setup-go.md)]
27+
28+
#### Authorization
29+
30+
The authorization mechanism must have the necessary permissions to work with container properties or metadata. For authorization with Microsoft Entra ID (recommended), you need Azure RBAC built-in role **Storage Blob Data Reader** or higher for the *get* operations, and **Storage Blob Data Contributor** or higher for the *set* operations. To learn more, see the authorization guidance for [Get Container Properties](/rest/api/storageservices/get-container-properties#authorization), [Set Container Metadata](/rest/api/storageservices/set-container-metadata#authorization), or [Get Container Metadata](/rest/api/storageservices/get-container-metadata#authorization).
31+
32+
## About properties and metadata
33+
34+
- **System properties**: System properties exist on each Blob Storage resource. Some of them can be read or set, while others are read-only. Behind the scenes, some system properties correspond to certain standard HTTP headers. The Azure Storage client library for Go maintains these properties for you.
35+
36+
- **User-defined metadata**: User-defined metadata consists of one or more name-value pairs that you specify for a Blob storage resource. You can use metadata to store additional values with the resource. Metadata values are for your own purposes only, and don't affect how the resource behaves.
37+
38+
Metadata name/value pairs are valid HTTP headers and should adhere to all restrictions governing HTTP headers. For more information about metadata naming requirements, see [Metadata names](/rest/api/storageservices/naming-and-referencing-containers--blobs--and-metadata#metadata-names).
39+
40+
## Retrieve container properties
41+
42+
To retrieve container properties, call the following method from a container client object:
43+
44+
- [GetProperties](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/container#Client.GetProperties)
45+
46+
The following code example fetches a container's system properties and writes some of the property values to a console window:
47+
48+
:::code language="go" source="~/blob-devguide-go/cmd/container-properties-metadata/container_properties_metadata.go" id="snippet_get_container_properties":::
49+
50+
## Set and retrieve metadata
51+
52+
You can specify metadata as one or more name-value pairs on a blob or container resource. To set metadata, call the following method from a container client object:
53+
54+
- [SetMetadata](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/container#Client.SetMetadata)
55+
56+
Setting container metadata overwrites all existing metadata associated with the container. It's not possible to modify an individual name-value pair.
57+
58+
The following code example sets metadata on a container:
59+
60+
:::code language="go" source="~/blob-devguide-go/cmd/container-properties-metadata/container_properties_metadata.go" id="snippet_set_container_metadata":::
61+
62+
To retrieve metadata, call the following method from a container client object:
63+
64+
- [GetProperties](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/container#Client.GetProperties)
65+
66+
Metadata is included in the response from `GetProperties`. The following example reads in metadata values and writes them to a console window:
67+
68+
:::code language="go" source="~/blob-devguide-go/cmd/container-properties-metadata/container_properties_metadata.go" id="snippet_get_container_metadata":::
69+
70+
[!INCLUDE [storage-dev-guide-code-samples-note-go](../../../includes/storage-dev-guides/storage-dev-guide-code-samples-note-go.md)]
71+
72+
## Resources
73+
74+
To learn more about setting and retrieving container properties and metadata using the Azure Blob Storage client module for Go, see the following resources.
75+
76+
### Code samples
77+
78+
- View [code samples](https://github.com/Azure-Samples/blob-storage-devguide-go/blob/main/cmd/container-properties-metadata/container_properties_metadata.go) from this article (GitHub)
79+
80+
### REST API operations
81+
82+
The Azure SDK for Go contains libraries that build on top of the Azure REST API, allowing you to interact with REST API operations through familiar Go paradigms. The client library methods for setting and retrieving properties and metadata use the following REST API operations:
83+
84+
- [Get Container Properties](/rest/api/storageservices/get-container-properties) (REST API)
85+
- [Set Container Metadata](/rest/api/storageservices/set-container-metadata) (REST API)
86+
- [Get Container Metadata](/rest/api/storageservices/get-container-metadata) (REST API)
87+
88+
The `get_container_properties` method retrieves container properties and metadata by calling both the [Get Container Properties](/rest/api/storageservices/get-container-properties) operation and the [Get Container Metadata](/rest/api/storageservices/get-container-metadata) operation.
89+
90+
[!INCLUDE [storage-dev-guide-resources-go](../../../includes/storage-dev-guides/storage-dev-guide-resources-go.md)]

0 commit comments

Comments
 (0)