Azure SDK for Go - Installation

Install the Azure SDK for Go and set up your development environment.

Prerequisites

1. Install Go

The Azure SDK for Go requires a recent version of Go. We recommend using the latest stable release. If you don't have Go installed, download and install it from the official Go website.

Verify your installation by running:

go version

2. Set up your Go Workspace

Ensure your Go environment is properly configured. This typically involves setting the GOPATH environment variable, although with Go Modules (introduced in Go 1.11), this is less critical for typical project setups.

If you are using Go Modules, you don't need a strict workspace setup. Just make sure Go is in your system's PATH.

Installing the SDK

1. Initialize your Go Module

Navigate to your project's root directory and initialize a Go module. Replace your_module_path with your desired module path (e.g., github.com/yourusername/yourproject).

go mod init your_module_path

2. Add SDK Packages

You can add specific Azure SDK packages to your project as needed. For example, to add the Azure Blob Storage client library:

go get github.com/Azure/azure-sdk-for-go/sdk/storage/azblob

To add the Azure Identity package for authentication:

go get github.com/Azure/azure-sdk-for-go/sdk/azidentity

The Go toolchain will automatically download and manage these dependencies.

3. Import Packages in your Code

In your Go source files, import the necessary Azure SDK packages:

package main

import (
	"fmt"

	"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
)

func main() {
	fmt.Println("Azure SDK for Go installed and ready!")
	// Your Azure SDK code here
}
Note: The Azure SDK for Go uses a modular structure. You import only the packages you require, making your projects lighter and more efficient.

Updating the SDK

To update an existing package to its latest version, run:

go get -u github.com/Azure/azure-sdk-for-go/sdk/storage/azblob

To update all your Go modules to their latest compatible versions:

go get -u ./...

Next Steps