Access Microsoft Azure from Go

Posted: , Modified:   Go Microsoft Azure Swagger

Summary

.NET is the most common way to access Microsoft Azure but I’ve investigated how to access Azure from Go. This post summaries my result.

Microsoft Azure SDK for Go

Microsoft Azure SDK for Go and Azure Storage SDK for Go are official SDK provided by Microsoft. The second one is separated from the first one and focusing Storage APIs. If we could use them, it seems the best way but both libraries are still preview edition.

Azure Storage SDK for Go seems providing minimum functionality but Microsoft Azure SDK for Go doesn’t yet. For example, I couldn’t find APIs to create a batch pool.

Thus, we need to find another way, using the following Azure REST API Specifications.

Azure REST API Specifications

Azure REST API Specifications is a set of REST API definitions for Azure. This repository is referred from not only Go users but also other language users, such as Node.js. It means more people are contributing this repository than SDKs for Go.

If we get REST API definitions, we can generate bindings for any language by Swagger, including Go of course.

To generate Go source code from those API definitions, we use go-swagger; and we can download it by go get command:

$ go get -u github.com/go-swagger/go-swagger/cmd/swagger

Then, for example, the following command generates Go source code for Azure Compute APIs:

$ swagger generate client \
	-f https://raw.githubusercontent.com/Azure/azure-rest-api-specs/master/arm-compute/2016-04-30-preview/swagger/compute.json \
	-t compute

However, I’m not sure it is from a bug of Azure REST API Specifications or go-swagger command, but sometimes swagger command fails. In such a case, we need to try other versions.