Skip to content
Golang Heroku API Client
Go Ruby
Find file
Latest commit ee4032d Aug 10, 2015 @bgentry Merge pull request #17 from cee-dub/master
Remove deprecated Google Code import path
Failed to load latest commit information.
gen always use correct HTTP method from schema May 19, 2014
.travis.yml update Godeps and .travis.yml to Go 1.2 Dec 10, 2013
Godeps update Godeps and .travis.yml to Go 1.2 Dec 10, 2013
LICENSE shout out to @kr and the API team Jan 7, 2014
README.md shout out to @kr and the API team Jan 7, 2014
account.go improvements to determining func args and their respective comments May 1, 2014
account_feature.go schema update, version 0.5.0 Jan 26, 2014
addon.go
addon_service.go Everything is generating and building! Nov 14, 2013
app.go Use pointers to option structs. Dec 18, 2013
app_feature.go improvements to determining func args and their respective comments May 1, 2014
app_test.go goimports Feb 4, 2014
app_transfer.go Everything is generating and building! Nov 14, 2013
collaborator.go improvements to determining func args and their respective comments May 1, 2014
config_var.go improvements to determining func args and their respective comments May 1, 2014
doc.go document ListRange Dec 19, 2013
domain.go improvements to determining func args and their respective comments May 1, 2014
dyno.go improvements to determining func args and their respective comments May 1, 2014
formation.go improvements to determining func args and their respective comments May 1, 2014
heroku.go Remove deprecated Google Code import path Aug 10, 2015
heroku_test.go
key.go ssl key 'email' renamed to 'comment' May 7, 2014
log_drain.go improvements to determining func args and their respective comments May 1, 2014
log_session.go improvements to determining func args and their respective comments May 1, 2014
oauth_authorization.go
oauth_client.go
oauth_token.go Everything is generating and building! Nov 14, 2013
organization.go orgs stuff Apr 30, 2014
organization_app.go add personal option to create org app, v0.10.1 May 14, 2014
organization_app_collaborator.go improvements to determining func args and their respective comments May 1, 2014
organization_member.go always use correct HTTP method from schema May 19, 2014
plan.go
rate_limit.go
region.go Everything is generating and building! Nov 14, 2013
release.go improvements to determining func args and their respective comments May 1, 2014
slug.go improvements to determining func args and their respective comments May 1, 2014
ssl_endpoint.go improvements to determining func args and their respective comments May 1, 2014
stack.go Everything is generating and building! Nov 14, 2013

README.md

heroku-go

An API client interface for Heroku for the Go (golang) programming language.

Build Status GoDoc

Background

This package provides a complete interface to all of the Heroku Platform API v3 actions, and is almost entirely auto-generated based on the API's JSON Schema. The exceptions are the files heroku.go, heroku_test.go, and app_test.go, as well as the generator itself. All models are auto-generated by the Ruby script in gen/gen.rb.

The client leverages Go's powerful net/http Client. That means that, out-of-the-box, it has keep-alive support and the ability to handle many concurrent requests from different goroutines.

You should have at least some understanding of Heroku and its Platform API.

Installation

This package is targeted towards Go 1.2 or later, though it may work on earlier versions as well.

Run go get github.com/bgentry/heroku-go to download, build, and install the package.

Getting Started

To use the client, first add it to your Go file's imports list:

import (
  "github.com/bgentry/heroku-go"
)

Then create a Client object and make calls to it:

client := heroku.Client{Username: "email@me.com", Password: "my-api-key"}

// pass nil for options if you don't need to set any optional params
app, err := client.AppCreate(nil)
if err != nil {
  panic(err)
}
fmt.Println("Created", app.Name)

// Output:
// Created dodging-samurai-42

That's it! Here is a more advanced example that also sets some options on the new app:

name := "myapp"
region := "region"

// Optional values need to be provided as pointers. If a field in an option
// struct is nil (not provided), the option is omitted from the API request.
opts := heroku.AppCreateOpts{Name: &name, Region: &region}

// Create an app with options set:
app2, err := client.AppCreate(&opts)
if err != nil {
  // if this is a heroku.Error, it will contain details about the error
  if hkerr, ok := err.(heroku.Error); ok {
    panic(fmt.Sprintf("Error id=%s message=%q", hkerr.Id, hkerr))
  }
}
fmt.Printf("created app2: name=%s region=%s", app2.Name, app2.Region.Name)

// Output:
// created app2: name=myapp region=eu

Optional Parameters

Many of the Heroku Platform API actions have optional parameters. For example, when creating an app, you can either specify a custom name, or allow the API to choose a random haiku name for your app.

Optional parameters in heroku-go are always provided to functions as a pointer to a struct, such as AppCreateOpts for the function AppCreate(). If you do not wish to set any optional parameters, simply provide a nil in place of the options struct, and the options will be omitted from the API request entirely. For any individual options that you don't want to set, simply leave them as nil, and they will be omitted from the API request.

List Ranges & Sorting

Results from the Heroku API are paginated. You can specify a field for sorting and adjust the maximum number of records returned by providing a ListRange to API calls that list objects:

apps, err = client.AppList(&heroku.ListRange{Field: "name", Max: 1000})

Note Field is required when setting any range options.

Documentation

More detailed documentation is available on godoc.

Thank You

A special thanks goes out to Keith Rarick for writing much of the base API client as part of hk. I also want to thank the Heroku API team for making their API available in JSON schema and for the early version of heroics, on which this generator is based.

Something went wrong with that request. Please try again.