or run

tessl search
Log in

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
golangpkg:golang/github.com/Azure/azure-sdk-for-go/sdk/storage/azqueue/v2@v2.0.1

docs

error-handling.mdindex.mdqueue-client.mdsas.mdservice-client.md
tile.json

tessl/golang-github-com-azure-azure-sdk-for-go-sdk-storage-azqueue-v2

tessl install tessl/golang-github-com-azure-azure-sdk-for-go-sdk-storage-azqueue-v2@2.0.1

Azure Queue Storage SDK for Go provides comprehensive client library for interacting with Azure's cloud-based message queue service including queue management, message operations, and multiple authentication methods.

service-client.mddocs/

Service Client

ServiceClient represents interaction with an Azure storage account. It provides account-level operations including queue management, service properties configuration, and statistics retrieval.

Capabilities

Client Creation

Create ServiceClient instances with various authentication methods.

// Create service client with Azure AD credential
func NewServiceClient(serviceURL string, cred azcore.TokenCredential, options *ClientOptions) (*ServiceClient, error)

// Create service client with shared key credential
func NewServiceClientWithSharedKeyCredential(serviceURL string, cred *SharedKeyCredential, options *ClientOptions) (*ServiceClient, error)

// Create service client from connection string
func NewServiceClientFromConnectionString(connectionString string, options *ClientOptions) (*ServiceClient, error)

// Create service client for anonymous/SAS access
func NewServiceClientWithNoCredential(serviceURL string, options *ClientOptions) (*ServiceClient, error)

Usage Examples:

import (
    "github.com/Azure/azure-sdk-for-go/sdk/azidentity"
    "github.com/Azure/azure-sdk-for-go/sdk/storage/azqueue/v2"
)

// Azure AD authentication (recommended)
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
    // handle error
}
serviceClient, err := azqueue.NewServiceClient(
    "https://myaccount.queue.core.windows.net/",
    cred,
    nil,
)

// Shared key authentication
sharedKeyCred, err := azqueue.NewSharedKeyCredential("myaccount", "mykey")
if err != nil {
    // handle error
}
serviceClient, err = azqueue.NewServiceClientWithSharedKeyCredential(
    "https://myaccount.queue.core.windows.net/",
    sharedKeyCred,
    nil,
)

// Connection string authentication
serviceClient, err = azqueue.NewServiceClientFromConnectionString(
    "DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=mykey;EndpointSuffix=core.windows.net",
    nil,
)

// No credential (for SAS URLs)
serviceClient, err = azqueue.NewServiceClientWithNoCredential(
    "https://myaccount.queue.core.windows.net/?<sas-token>",
    nil,
)

Get Service URL

Retrieve the service endpoint URL.

func (s *ServiceClient) URL() string

Usage:

url := serviceClient.URL()
// Returns: "https://myaccount.queue.core.windows.net/"

Create Queue Client

Create a QueueClient for a specific queue.

// Create queue client for specified queue name
func (s *ServiceClient) NewQueueClient(queueName string) *QueueClient

Usage:

queueClient := serviceClient.NewQueueClient("myqueue")
// QueueClient URL: "https://myaccount.queue.core.windows.net/myqueue"

Create Queue

Create a new queue within the storage account.

func (s *ServiceClient) CreateQueue(ctx context.Context, queueName string, options *CreateOptions) (CreateResponse, error)

// Options for queue creation
type CreateOptions struct {
    // Optional. User-defined name-value pairs associated with the queue
    Metadata map[string]*string
}

// Response type
type CreateResponse = generated.QueueClientCreateResponse

Usage:

import "context"

// Create queue without metadata
_, err := serviceClient.CreateQueue(context.TODO(), "myqueue", nil)
if err != nil {
    // handle error
}

// Create queue with metadata
metadata := map[string]*string{
    "department": to.Ptr("engineering"),
    "project":    to.Ptr("analytics"),
}
_, err = serviceClient.CreateQueue(context.TODO(), "myqueue", &azqueue.CreateOptions{
    Metadata: metadata,
})

Notes:

  • If a queue with the same name exists and metadata matches, returns status code 204 (No Content)
  • If metadata doesn't match, operation fails with status code 409 (Conflict)
  • Queue names must follow Azure naming rules (lowercase, alphanumeric, hyphens)

Delete Queue

Delete a queue from the storage account.

func (s *ServiceClient) DeleteQueue(ctx context.Context, queueName string, options *DeleteOptions) (DeleteResponse, error)

// Options for queue deletion
type DeleteOptions struct {
    // Empty struct - no options currently available
}

// Response type
type DeleteResponse = generated.QueueClientDeleteResponse

Usage:

_, err := serviceClient.DeleteQueue(context.TODO(), "myqueue", nil)
if err != nil {
    // handle error
}

List Queues

List queues in the storage account with pagination support.

// Create pager for listing queues
func (s *ServiceClient) NewListQueuesPager(o *ListQueuesOptions) *runtime.Pager[ListQueuesResponse]

// Options for listing queues
type ListQueuesOptions struct {
    // Include metadata in results
    Include ListQueuesInclude

    // Continuation token from previous listing operation
    Marker *string

    // Maximum number of results to return (default/max: 5000)
    MaxResults *int32

    // Filter queues whose name begins with specified prefix
    Prefix *string
}

// What to include in queue listings
type ListQueuesInclude struct {
    // Include metadata for each queue
    Metadata bool
}

// Response type
type ListQueuesResponse = generated.ServiceClientListQueuesSegmentResponse

Usage:

import "context"

// List all queues
pager := serviceClient.NewListQueuesPager(nil)
for pager.More() {
    page, err := pager.NextPage(context.TODO())
    if err != nil {
        // handle error
    }

    for _, queue := range page.Queues {
        fmt.Printf("Queue: %s\n", *queue.Name)
    }
}

// List queues with prefix and metadata
pager = serviceClient.NewListQueuesPager(&azqueue.ListQueuesOptions{
    Prefix: to.Ptr("prod-"),
    Include: azqueue.ListQueuesInclude{
        Metadata: true,
    },
    MaxResults: to.Ptr(int32(100)),
})

for pager.More() {
    page, err := pager.NextPage(context.TODO())
    if err != nil {
        // handle error
    }

    for _, queue := range page.Queues {
        fmt.Printf("Queue: %s, Metadata: %v\n", *queue.Name, queue.Metadata)
    }
}

Notes:

  • Queues are returned in lexicographic order
  • Listing may cross partition boundaries, so service may return fewer results than MaxResults
  • Use the Marker field for continuation across multiple requests

Get Service Properties

Retrieve service-level properties including CORS, logging, and metrics configuration.

func (s *ServiceClient) GetServiceProperties(ctx context.Context, o *GetServicePropertiesOptions) (GetServicePropertiesResponse, error)

// Options for getting service properties
type GetServicePropertiesOptions struct {
    // Empty struct - no options currently available
}

// Response type
type GetServicePropertiesResponse = generated.ServiceClientGetPropertiesResponse

Usage:

resp, err := serviceClient.GetServiceProperties(context.TODO(), nil)
if err != nil {
    // handle error
}

props := resp.StorageServiceProperties
if props.Logging != nil {
    fmt.Printf("Logging version: %s\n", *props.Logging.Version)
}
if props.HourMetrics != nil {
    fmt.Printf("Hour metrics enabled: %t\n", *props.HourMetrics.Enabled)
}

Set Service Properties

Configure service-level properties including CORS, logging, and metrics.

func (s *ServiceClient) SetProperties(ctx context.Context, o *SetPropertiesOptions) (SetPropertiesResponse, error)

// Options for setting service properties
type SetPropertiesOptions struct {
    // CORS rules for cross-domain access
    CORS []*CORSRule

    // Hour-level metrics configuration
    HourMetrics *Metrics

    // Azure Analytics logging settings
    Logging *Logging

    // Minute-level metrics configuration
    MinuteMetrics *Metrics
}

// Response type
type SetPropertiesResponse = generated.ServiceClientSetPropertiesResponse

// CORS rule definition
type CORSRule = generated.CORSRule

// Metrics configuration
type Metrics = generated.Metrics

// Logging configuration
type Logging = generated.Logging

// Retention policy
type RetentionPolicy = generated.RetentionPolicy

Usage:

// Enable logging
logging := &azqueue.Logging{
    Version: to.Ptr("1.0"),
    Delete:  to.Ptr(true),
    Read:    to.Ptr(true),
    Write:   to.Ptr(true),
    RetentionPolicy: &azqueue.RetentionPolicy{
        Enabled: to.Ptr(true),
        Days:    to.Ptr(int32(7)),
    },
}

// Configure metrics
metrics := &azqueue.Metrics{
    Version: to.Ptr("1.0"),
    Enabled: to.Ptr(true),
    RetentionPolicy: &azqueue.RetentionPolicy{
        Enabled: to.Ptr(true),
        Days:    to.Ptr(int32(7)),
    },
}

// Set properties
_, err := serviceClient.SetProperties(context.TODO(), &azqueue.SetPropertiesOptions{
    Logging:       logging,
    HourMetrics:   metrics,
    MinuteMetrics: metrics,
})
if err != nil {
    // handle error
}

Notes:

  • If an element is nil, existing settings for that functionality are preserved
  • CORS rules enable web applications in one domain to access resources in another domain

Get Statistics

Retrieve statistics related to replication for the Queue service.

func (s *ServiceClient) GetStatistics(ctx context.Context, o *GetStatisticsOptions) (GetStatisticsResponse, error)

// Options for getting statistics
type GetStatisticsOptions struct {
    // Empty struct - no options currently available
}

// Response type
type GetStatisticsResponse = generated.ServiceClientGetStatisticsResponse

// Storage service statistics
type StorageServiceStats = generated.StorageServiceStats

// Geo-replication information
type GeoReplication = generated.GeoReplication

// Geo-replication status enum
type GeoReplicationStatus = generated.GeoReplicationStatus

Geo-Replication Status Constants:

const (
    GeoReplicationStatusLive        GeoReplicationStatus = "live"
    GeoReplicationStatusBootstrap   GeoReplicationStatus = "bootstrap"
    GeoReplicationStatusUnavailable GeoReplicationStatus = "unavailable"
)

Usage:

resp, err := serviceClient.GetStatistics(context.TODO(), nil)
if err != nil {
    // handle error
}

stats := resp.StorageServiceStats
if stats.GeoReplication != nil {
    fmt.Printf("Status: %s\n", *stats.GeoReplication.Status)
    fmt.Printf("Last sync time: %s\n", stats.GeoReplication.LastSyncTime.Format(time.RFC3339))
}

Notes:

  • Only available for read-access geo-redundant replication (RA-GRS)
  • Must call the secondary endpoint to retrieve statistics

Generate Account SAS URL

Generate a SAS URL for account-level access.

func (s *ServiceClient) GetSASURL(resources sas.AccountResourceTypes, permissions sas.AccountPermissions, expiry time.Time, o *GetSASURLOptions) (string, error)

// Options for SAS URL generation
type GetSASURLOptions struct {
    // Optional start time for SAS validity
    StartTime *time.Time
}

Usage:

import (
    "time"
    "github.com/Azure/azure-sdk-for-go/sdk/storage/azqueue/v2/sas"
)

// Define resource types
resources := sas.AccountResourceTypes{
    Service:   true,
    Container: true,
    Object:    true,
}

// Define permissions
permissions := sas.AccountPermissions{
    Read:   true,
    Write:  true,
    List:   true,
    Create: true,
}

// Generate SAS URL valid for 1 hour
expiry := time.Now().Add(1 * time.Hour)
sasURL, err := serviceClient.GetSASURL(resources, permissions, expiry, nil)
if err != nil {
    // handle error
}

fmt.Println(sasURL)
// Use sasURL to create a new client with SAS authentication

Notes:

  • Only works if ServiceClient was created with SharedKeyCredential
  • The generated URL includes the SAS token as query parameters