Home Documentation Azure Go SDK Reference

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)

Azure Storage

Azure Cosmos DB

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.

Returns the created/updated resource group and an error.

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.

Returns a page of resource groups and an error.