|
| 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/26/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 | +[!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 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). |
| 31 | + |
| 32 | +[!INCLUDE [storage-dev-guide-about-blob-tags](../../../includes/storage-dev-guides/storage-dev-guide-about-blob-tags.md)] |
| 33 | + |
| 34 | +## Set tags |
| 35 | + |
| 36 | +[!INCLUDE [storage-dev-guide-auth-set-blob-tags](../../../includes/storage-dev-guides/storage-dev-guide-auth-set-blob-tags.md)] |
| 37 | + |
| 38 | +You can set tags by using the following method: |
| 39 | + |
| 40 | +- [SetTags](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/blob#Client.SetTags) |
| 41 | + |
| 42 | +The tags specified in this method replace any 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: |
| 43 | + |
| 44 | +:::code language="go" source="~/blob-devguide-go/cmd/blob-index-tags/blob_index_tags.go" id="snippet_set_blob_tags"::: |
| 45 | + |
| 46 | +You can remove all tags by calling `SetTags` with no tags, as shown in the following example: |
| 47 | + |
| 48 | +:::code language="go" source="~/blob-devguide-go/cmd/blob-index-tags/blob_index_tags.go" id="snippet_clear_blob_tags"::: |
| 49 | + |
| 50 | +## Get tags |
| 51 | + |
| 52 | +[!INCLUDE [storage-dev-guide-auth-get-blob-tags](../../../includes/storage-dev-guides/storage-dev-guide-auth-get-blob-tags.md)] |
| 53 | + |
| 54 | +You can get tags by using the following method: |
| 55 | + |
| 56 | +- [GetTags](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/blob#Client.GetTags) |
| 57 | + |
| 58 | +The following example shows how to retrieve and iterate over the blob's tags: |
| 59 | + |
| 60 | +:::code language="go" source="~/blob-devguide-go/cmd/blob-index-tags/blob_index_tags.go" id="snippet_get_blob_tags"::: |
| 61 | + |
| 62 | +## Filter and find data with blob index tags |
| 63 | + |
| 64 | +[!INCLUDE [storage-dev-guide-auth-filter-blob-tags](../../../includes/storage-dev-guides/storage-dev-guide-auth-filter-blob-tags.md)] |
| 65 | + |
| 66 | +> [!NOTE] |
| 67 | +> 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). |
| 68 | +
|
| 69 | +You can filter blob data based on index tags by using the following method: |
| 70 | + |
| 71 | +- [FilterBlobs ](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/storage/[email protected]/container#Client.FilterBlobs) |
| 72 | + |
| 73 | +The following example finds and lists all blobs tagged as an image: |
| 74 | + |
| 75 | +:::code language="go" source="~/blob-devguide-go/cmd/blob-index-tags/blob_index_tags.go" id="snippet_find_blobs_by_tags"::: |
| 76 | + |
| 77 | +[!INCLUDE [storage-dev-guide-code-samples-note-go](../../../includes/storage-dev-guides/storage-dev-guide-code-samples-note-go.md)] |
| 78 | + |
| 79 | +## Resources |
| 80 | + |
| 81 | +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. |
| 82 | + |
| 83 | +### Code samples |
| 84 | + |
| 85 | +- 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) |
| 86 | + |
| 87 | +### REST API operations |
| 88 | + |
| 89 | +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: |
| 90 | + |
| 91 | +- [Get Blob Tags](/rest/api/storageservices/get-blob-tags) (REST API) |
| 92 | +- [Set Blob Tags](/rest/api/storageservices/set-blob-tags) (REST API) |
| 93 | +- [Find Blobs by Tags](/rest/api/storageservices/find-blobs-by-tags) (REST API) |
| 94 | + |
| 95 | +[!INCLUDE [storage-dev-guide-resources-go](../../../includes/storage-dev-guides/storage-dev-guide-resources-go.md)] |
| 96 | + |
| 97 | +### See also |
| 98 | + |
| 99 | +- [Manage and find Azure Blob data with blob index tags](storage-manage-find-blobs.md) |
| 100 | +- [Use blob index tags to manage and find data on Azure Blob Storage](storage-blob-index-how-to.md) |
0 commit comments