This is a simple example of a zero-dependency Go API application running on Heroku
heroku-go-example -- Repository / package name
├── Makefile -- Targets for local development (optional)
├── Procfile -- Defines a single `web` process
├── README.md -- This file
├── bin
│ └── heroku-go-example -- The locally-built binary (gitignored)
├── main.go -- The main Go application
└── vendor
└── vendor.json -- Buildpack identification / Heroku configuration [1]
When the application is deployed, the Heroku Go buildpack will run go install .
to build and install your application to /app/bin
. We want to mimic this in local development, so the run
target in the Makefile
will:
- Compile
main.go
tobin/heroku-go-example
-- this is important because Go will use the pacakge name (heroku-go-example
) when creating the binary. - Prepend the
./bin
directory to the$PATH
and runheroku local
. This allows theweb
process in theProcfile
to find theheroku-go-example
binary.
This is all done for you by running make
since run
is the default target.
$ heroku apps:create heroku-go-example
$ git push heroku master
GET: curl -s https://heroku-go-example.herokuapp.com | jq .
POST: curl -s -d '{"key":"value"}' https://heroku-go-example.herokuapp.com | jq .