We’ve recently been using the Go programming language internally for a couple of projects and we’ve had the need to interact with our own API, so we’ve started writing a Go client library.
It’s currently a little rough and incomplete, but it’s already useful for managing servers, images, cloud ips, and groups so we’ve released it.
Here’s an example of it in action:
package main
import (
"fmt"
"github.com/brightbox/gobrightbox"
"golang.org/x/oauth2"
"golang.org/x/oauth2/clientcredentials"
)
// Authenticate using an API Client identifier and secret, and get a list of
// servers
func main() {
apiUrl := "https://api.gb1.brightbox.com"
clientId := "cli-xxxxx"
clientSecret := "somesecret"
// Setup OAuth2 authentication
conf := clientcredentials.Config{
ClientID: clientId,
ClientSecret: clientSecret,
Scopes: []string{},
TokenURL: apiUrl + "/token",
}
oc := conf.Client(oauth2.NoContext)
// Setup connection to API
client, err := brightbox.NewClient(apiUrl, "", oc)
if err != nil {
fmt.Println(err)
return
}
// Get a list of servers
servers, err := client.Servers()
if err != nil {
fmt.Println(err)
return
}
for _, server := range servers {
fmt.Printf("id:%s name:%s\n", server.Id, server.Name)
}
}
Since it is in early development things may change but what’s available already is fairly stable. Bug reports and pull requests are of course fully welcomed.
If you want to see a more detailed example of it in use, see our upcoming Docker machine driver or our experimental go cli implementation.
As for our team’s opinion on Go as a programming language? Currently somewhat mixed. Let’s leave it at that for now :)