Skip to content

Commit 8afe80f

Browse files
Add blob index tag article for Go
1 parent 0186140 commit 8afe80f

File tree

1 file changed

+102
-0
lines changed

1 file changed

+102
-0
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
---
2+
title: Use blob index tags to manage and find data with Go
3+
titleSuffix: Azure Storage
4+
description: Learn how to categorize, manage, and query for blob objects by using the Go client module.
5+
services: storage
6+
author: pauljewellmsft
7+
8+
ms.author: pauljewell
9+
ms.date: 06/10/2024
10+
ms.service: azure-blob-storage
11+
ms.topic: how-to
12+
ms.devlang: golang
13+
ms.custom: devx-track-go, devguide-go
14+
---
15+
16+
# Use blob index tags to manage and find data with Go
17+
18+
[!INCLUDE [storage-dev-guide-selector-index-tags](../../../includes/storage-dev-guides/storage-dev-guide-selector-index-tags.md)]
19+
20+
This article shows how to use blob index tags to manage and find data using 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+
To learn about setting blob index tags using asynchronous APIs, see [Set blob index tags asynchronously](#set-blob-index-tags-asynchronously).
23+
24+
[!INCLUDE [storage-dev-guide-prereqs-go](../../../includes/storage-dev-guides/storage-dev-guide-prereqs-go.md)]
25+
26+
## Set up your environment
27+
28+
[!INCLUDE [storage-dev-guide-project-setup-go](../../../includes/storage-dev-guides/storage-dev-guide-project-setup-go.md)]
29+
30+
#### Authorization
31+
32+
The authorization mechanism must have the necessary permissions to work with blob index tags. For authorization with Microsoft Entra ID (recommended), you need Azure RBAC built-in role **Storage Blob Data Owner** or higher. To learn more, see the authorization guidance for [Get Blob Tags](/rest/api/storageservices/get-blob-tags#authorization), [Set Blob Tags](/rest/api/storageservices/set-blob-tags#authorization), or [Find Blobs by Tags](/rest/api/storageservices/find-blobs-by-tags#authorization).
33+
34+
[!INCLUDE [storage-dev-guide-about-blob-tags](../../../includes/storage-dev-guides/storage-dev-guide-about-blob-tags.md)]
35+
36+
## Set tags
37+
38+
[!INCLUDE [storage-dev-guide-auth-set-blob-tags](../../../includes/storage-dev-guides/storage-dev-guide-auth-set-blob-tags.md)]
39+
40+
You can set tags by using the following method:
41+
42+
- [SetTags](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/blob#Client.SetTags)
43+
44+
The specified tags in this method will replace existing tags. If existing values must be preserved, they must be downloaded and included in the call to this method. The following example shows how to set tags:
45+
46+
:::code language="go" source="~/blob-devguide-go/cmd/blob-index-tags/blob_index_tags.go" id="snippet_set_blob_tags":::
47+
48+
You can remove all tags by calling `SetTags` with no tags, as shown in the following example:
49+
50+
:::code language="go" source="~/blob-devguide-go/cmd/blob-index-tags/blob_index_tags.go" id="snippet_clear_blob_tags":::
51+
52+
## Get tags
53+
54+
[!INCLUDE [storage-dev-guide-auth-get-blob-tags](../../../includes/storage-dev-guides/storage-dev-guide-auth-get-blob-tags.md)]
55+
56+
You can get tags by using the following method:
57+
58+
- [GetTags](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/blob#Client.GetTags)
59+
60+
The following example shows how to retrieve and iterate over the blob's tags:
61+
62+
:::code language="go" source="~/blob-devguide-go/cmd/blob-index-tags/blob_index_tags.go" id="snippet_get_blob_tags":::
63+
64+
## Filter and find data with blob index tags
65+
66+
[!INCLUDE [storage-dev-guide-auth-filter-blob-tags](../../../includes/storage-dev-guides/storage-dev-guide-auth-filter-blob-tags.md)]
67+
68+
> [!NOTE]
69+
> You can't use index tags to retrieve previous versions. Tags for previous versions aren't passed to the blob index engine. For more information, see [Conditions and known issues](storage-manage-find-blobs.md#conditions-and-known-issues).
70+
71+
You can filter blob data based on index tags by using the following method:
72+
73+
- [FilterBlobs](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/storage/[email protected]/container#Client.FilterBlobs)
74+
75+
The following example finds and lists all blobs tagged as an image:
76+
77+
:::code language="go" source="~/blob-devguide-go/cmd/blob-index-tags/blob_index_tags.go" id="snippet_find_blobs_by_tags":::
78+
79+
[!INCLUDE [storage-dev-guide-code-samples-note-go](../../../includes/storage-dev-guides/storage-dev-guide-code-samples-note-go.md)]
80+
81+
## Resources
82+
83+
To learn more about how to use index tags to manage and find data using the Azure Blob Storage client library for Go, see the following resources.
84+
85+
### Code samples
86+
87+
- View [code samples](https://github.com/Azure-Samples/blob-storage-devguide-go/blob/main/cmd/blob-index-tags/blob-index-tags.go) from this article (GitHub)
88+
89+
### REST API operations
90+
91+
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 managing and using blob index tags use the following REST API operations:
92+
93+
- [Get Blob Tags](/rest/api/storageservices/get-blob-tags) (REST API)
94+
- [Set Blob Tags](/rest/api/storageservices/set-blob-tags) (REST API)
95+
- [Find Blobs by Tags](/rest/api/storageservices/find-blobs-by-tags) (REST API)
96+
97+
[!INCLUDE [storage-dev-guide-resources-go](../../../includes/storage-dev-guides/storage-dev-guide-resources-go.md)]
98+
99+
### See also
100+
101+
- [Manage and find Azure Blob data with blob index tags](storage-manage-find-blobs.md)
102+
- [Use blob index tags to manage and find data on Azure Blob Storage](storage-blob-index-how-to.md)

0 commit comments

Comments
 (0)