Deploying Go
Choose Go (--framework go). Commit a Go modules project with go.mod at
the selected app root, plus go.sum when your dependencies require it.
This is a quick guide for an existing project. For a complete hello → database → worker → storage walkthrough, follow the Go tutorial.
Here is a minimal web server:
package main
import (
"fmt"
"log"
"net/http"
"os"
)
func main() {
http.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "ok")
})
log.Fatal(http.ListenAndServe(":"+os.Getenv("PORT"), nil))
}
go mod init example.com/service
go mod tidy
paas apps create service --framework go --health-check-path /health
Commit and push your code. The builder compiles
the main packages and provides a web process for a single-binary app. Add a
Procfile when you need a different command or
multiple process types; compiled binaries are on the launch process’s PATH. For example:
web: service
For several main packages, the buildpack’s // +heroku install comment in
go.mod can select which package paths to compile. Keep the Procfile’s binary
names consistent with those packages.
Declare the compiler requirement in go.mod; see runtime
selection for exact pins, ranges, and the
toolchain distinction. The catalog lists
the deployed builder’s available releases and verified versions.
The platform disables Go’s VCS stamping during builds because the build sandbox
does not expose a normal writable Git checkout. This does not change module
dependency resolution. For build failures, check the requested compiler version,
module files, and package paths. For health failures, bind to all interfaces and
read the injected PORT, then ensure your configured health endpoint succeeds.