Go Go CloudShare SDK!

We are excited to announce the availability of our Go-SDK – a Golang wrapper for CloudShare’s REST API.

After Python, C# and Javascript, it’s about time we showed Golang some love.

gopher image

Getting Started

Eager Go developers, simply runĀ go get github.com/cloudshare/go-sdk/cloudshare and you’re all set.

The SDK is essentially a wrapper for our REST API. It takes care of all the authentication hassle and lets you get to work quickly, with minimal code.

Simple Example

Here is how to get a list of all your projects on CloudShare:

c := cloudshare.Client{
    APIKey: "your API key here",
    APIID: "your API id here",
}
var projects = []cloudshare.Project{}
apierr := c.GetProjects(&projects)

What’s Included

The Go SDK actually comes in two flavors: a generic REST API wrapper, with which you can execute any REST API call you find in the docs, and for the most commonly used API calls there are also typed Go structs and methods to make things extra easy.

Generic REST Calls

You can invoke any API call using the Request method of the Client:

c := cloudshare.Client{ ... }
apiresponse, apierror := c.Request("GET", "envs", nil, nil)

You can specify the HTTP method (Get, Put, etc.), an optional JSON body and optinal URL parameters. The result is a HTTP response:

type APIResponse struct {}
    StatusCode int
    Body       []byte
    Headers    http.Header
}

Typed API Calls

The simple example above is actually the same call, but using the typed method GetProjects, which returns a typed struct slice of Project instances.

Checkout the godoc for a list of all supported calls.

Bonus: cscurl

Developing against a RESTful API is a lot easier when you can use curl to test API calls. Included in the Go-SDK is a small CLI utility called cscurl, which is a curl-style tool for interacting with the CloudShare API. In essence, it takes care of the authentication part for you, which is harder to do with the standard curl utility.

The example above (getting a list of projects) can be done with cscurl from command-line like so:

$ cscurl https://use.cloudshare.com/api/v3/projects

(Keen observers may wonder how the example above just works, without supplying any credentials. They can be supplied as env-vars. cscurl --help shows how.)

Setup

You can grab cscurl from the SDK’s releases page.

Since it’s written in Go, and since Go is awesome, cscurl is available for Linux, Mac, Windows and both 32 & 64 bit.

Go get it

Go forth and hack away using our Go SDK. Fork it, play with it, let us know what you think. We eat our own dog-food, here at CloudShare, and the Go SDK is an essential part of two more Docker-related annoucements soon to come. Stay tuned.

Go run image

Adorable Creative Commons gopher images in this post by Renee French.