Azure SDK for Go Reference
Introduction
Welcome to the official reference documentation for the Azure SDK for Go. This SDK provides a comprehensive set of Go modules to interact with various Azure services.
Explore the available packages, understand common patterns, and find code examples to build robust cloud applications on Azure using Go.
Getting Started
To begin using the Azure SDK for Go, ensure you have Go installed. Then, you can add the SDK modules to your project:
go get github.com/Azure/azure-sdk-for-go/...
For most services, you will need to authenticate. The SDK supports several authentication methods, including Service Principals, Managed Identities, and Azure CLI credentials. Refer to the Authentication Guide for more details.
Packages
The Azure SDK for Go is organized into distinct packages, each corresponding to a specific Azure service or a set of related functionalities.
Azure Resource Manager (ARM)
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources- Manage Azure resources like resource groups, deployments, and policies.github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute- Interact with Azure Compute services, including virtual machines and disks.github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network- Manage Azure networking resources such as virtual networks, load balancers, and public IPs.
Azure Storage
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob- Access and manage Azure Blob Storage.github.com/Azure/azure-sdk-for-go/sdk/storage/azfile- Interact with Azure Files.github.com/Azure/azure-sdk-for-go/sdk/storage/azqueue- Use Azure Queue Storage.
Azure Cosmos DB
github.com/Azure/azure-sdk-for-go/sdk/data/azcosmos- Connect to and manage Azure Cosmos DB SQL API resources.
Azure Key Vault
github.com/Azure/azure-sdk-for-go/sdk/security/azkeyvault/secrets- Manage secrets in Azure Key Vault.github.com/Azure/azure-sdk-for-go/sdk/security/azkeyvault/keys- Manage cryptographic keys in Azure Key Vault.
Guides
Understand common patterns and best practices for using the Azure SDK for Go.
Authentication
Learn how to authenticate your Go applications with Azure using various credential types.
Error Handling
Implement robust error handling strategies with the Azure SDK for Go, leveraging Go's standard error patterns and specific Azure error types.
Retry Logic
Configure automatic retry policies for network requests to handle transient Azure service errors.
Examples
View practical code snippets demonstrating how to perform common tasks with the Azure SDK for Go.
Browse the official Azure SDK for Go samples repository for a comprehensive collection of examples.
Here's a simple example of listing blob containers in a storage account:
// Assuming you have an authenticated client:
// client, err := azblob.NewClient(...)
// List containers
pager := client.NewListContainersPager(nil)
for pager.More() {
page, err := pager.NextPage(ctx)
if err != nil {
log.Fatalf("failed to advance page: %v", err)
}
for _, container := range page.ContainerItems {
fmt.Printf("Container name: %s\n", *container.Name)
}
}
Package: github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources
This package provides clients for managing Azure Resource Manager resources.
Key Structs
ResourceGroup
Represents an Azure Resource Group.
ID string: The resource ID.Name string: The resource group name.Location string: The Azure region.Tags map[string]*string: User-defined tags.
DeploymentProperties
Properties of a deployment.
Template interface{}: The deployment template.Parameters interface{}: The deployment parameters.
Key Functions/Methods
NewResourceGroupsClient(credential azcore.TokenCredential, options *arm.ClientOptions) (*ResourceGroupsClient, error)
Creates a new instance of the ResourceGroupsClient.
credential: An Azure credential object.
options: Optional client configuration.
ResourceGroupsClient.CreateOrUpdate(ctx context.Context, resourceGroupName string, parameters ResourceGroup, options *arm.ClientOptions) (ResourceGroupsClientCreateOrUpdateResponse, error)
Creates or updates a resource group.
ctx: The context for the request.
resourceGroupName: The name of the resource group.
parameters: The resource group definition.
options: Optional client configuration.
ResourceGroupsClient.List(ctx context.Context, options *arm.ClientOptions) (ResourceGroupsClientListResponse, error)
Lists all resource groups in the current subscription.
ctx: The context for the request.
options: Optional client configuration.