Convert Figma logo to code with AI

Azure logoazure-sdk-for-go

This repository is for active development of the Azure SDK for Go. For consumers of the SDK we recommend visiting our public developer docs at:

1,590
821
1,590
266

Top Related Projects

Microsoft SQL server driver written in go language

Quick Overview

The Azure/azure-sdk-for-go repository is the official Azure SDK for the Go programming language. It provides a set of Go packages that enable developers to interact with various Azure services, allowing them to create, manage, and deploy Azure resources programmatically using Go.

Pros

  • Comprehensive coverage of Azure services
  • Regular updates and maintenance by Microsoft
  • Consistent API design across different Azure services
  • Extensive documentation and examples

Cons

  • Learning curve for developers new to Azure
  • Large codebase can be overwhelming for beginners
  • Some services may have limited functionality compared to other Azure SDKs
  • Occasional breaking changes between major versions

Code Examples

  1. Authenticating with Azure:
import (
    "github.com/Azure/azure-sdk-for-go/sdk/azidentity"
)

func main() {
    cred, err := azidentity.NewDefaultAzureCredential(nil)
    if err != nil {
        // Handle error
    }
    // Use cred for authenticating with Azure services
}
  1. Creating a resource group:
import (
    "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources"
)

func createResourceGroup(client *armresources.ResourceGroupsClient, name, location string) error {
    _, err := client.CreateOrUpdate(
        context.Background(),
        name,
        armresources.ResourceGroup{
            Location: &location,
        },
        nil,
    )
    return err
}
  1. Listing virtual machines:
import (
    "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute"
)

func listVMs(client *armcompute.VirtualMachinesClient, resourceGroup string) ([]*armcompute.VirtualMachine, error) {
    pager := client.NewListPager(resourceGroup, nil)
    var vms []*armcompute.VirtualMachine
    for pager.More() {
        page, err := pager.NextPage(context.Background())
        if err != nil {
            return nil, err
        }
        vms = append(vms, page.Value...)
    }
    return vms, nil
}

Getting Started

  1. Install the SDK:
go get -u github.com/Azure/azure-sdk-for-go/sdk/...
  1. Import the required packages in your Go code:
import (
    "github.com/Azure/azure-sdk-for-go/sdk/azidentity"
    "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources"
)
  1. Authenticate and create a client:
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
    // Handle error
}

client, err := armresources.NewResourceGroupsClient("<subscription-id>", cred, nil)
if err != nil {
    // Handle error
}
  1. Use the client to interact with Azure services:
result, err := client.Get(context.Background(), "<resource-group-name>", nil)
if err != nil {
    // Handle error
}
// Use the result

Competitor Comparisons

Microsoft SQL server driver written in go language

Pros of go-mssqldb

  • Focused specifically on Microsoft SQL Server connectivity
  • Lightweight and easy to integrate into Go projects
  • Active community support and regular updates

Cons of go-mssqldb

  • Limited to SQL Server operations only
  • Lacks broader Azure service integration capabilities
  • May require additional libraries for complex Azure-specific tasks

Code Comparison

go-mssqldb:

db, err := sql.Open("sqlserver", "server=localhost;user id=sa;password=secret")
if err != nil {
    log.Fatal(err)
}
defer db.Close()

azure-sdk-for-go:

client := sql.NewClient(subscriptionID)
ctx := context.Background()
server, err := client.CreateOrUpdate(ctx, resourceGroup, serverName, sql.Server{})
if err != nil {
    log.Fatal(err)
}

The go-mssqldb example shows a direct database connection, while the azure-sdk-for-go example demonstrates creating an Azure SQL Server resource. The azure-sdk-for-go provides a more comprehensive set of Azure services but requires more setup for basic database operations.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Azure SDK for Go

godoc

This repository is for active development of the Azure SDK for Go. For consumers of the SDK you can follow the links below to visit the documentation you are interested in

Getting Started

To get started with a module, see the README.md file located in the module's project folder. You can find these module folders grouped by service in the /sdk directory.

[!NOTE] Go 1.18 or later is required. You could download and install the latest version of Go from here. It will replace the existing Go on your machine. If you want to install multiple Go versions on the same machine, you could refer this doc.

[!NOTE] Projects are highly encouraged to use the latest version of Go. This ensures your product has all the latest security fixes and is included in Go's support lifecycle.

[!WARNING] The root azure-sdk-for-go Go module which contains subpaths of /services/**/mgmt/** (also known as track 1) is deprecated and no longer recieving support. See the migration guide to learn how to migrate to the current version.

Packages available

Each service can have both 'client' and 'management' modules. 'Client' modules are used to consume the service, whereas 'management' modules are used to configure and manage the service.

Client modules

Our client modules follow the Azure Go SDK guidelines. These modules allow you to use, consume, and interact with existing resources, for example, uploading a blob. They also share a number of core functionalities including retries, logging, transport protocols, authentication protocols, etc. that can be found in the azcore module.

You can find the most up-to-date list of new modules on our latest page.

[!NOTE] If you need to ensure your code is ready for production use one of the stable, non-beta modules.

Management modules

Similar to our client modules, the management modules follow the Azure Go SDK guidelines. All management modules are available at sdk/resourcemanager. These modules provide a number of core capabilities that are shared amongst all Azure SDKs, including the intuitive Azure Identity module, an HTTP Pipeline with custom policies, error-handling, distributed tracing, and much more.

To get started, please follow the quickstart guide here. To see the benefits of migrating and how to migrate to the new modules, please visit the migration guide.

You can find the most up to date list of all of the new packages on our page

[!NOTE] If you need to ensure your code is ready for production use one of the stable, non-beta modules. Also, if you are experiencing authentication issues with the management modules after upgrading certain packages, it's possible that you upgraded to the new versions of SDK without changing the authentication code. Please refer to the migration guide for proper instructions.

Samples

More code samples for using the management modules for Go SDK can be found in the following locations

Historical releases

Note that the latest modules from Microsoft are grouped by service in the /sdk directory. If you're using packages with prefix github.com/Azure/azure-sdk-for-go/services, github.com/Azure/azure-sdk-for-go/storage, github.com/Azure/azure-sdk-for-go/profiles, please consider migrating to the latest modules. You can find a mapping table from these historical releases to their equivalent here.

Reporting security issues and security bugs

Security issues and bugs should be reported privately, via email, to the Microsoft Security Response Center (MSRC) secure@microsoft.com. You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Further information, including the MSRC PGP key, can be found in the Security TechCenter.

Need help?

Community

Contribute

See CONTRIBUTING.md.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

Trademarks

This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft's Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.