Skip to content

Quick Start — Go

Deploy a Go app from git push to a live HTTPS URL in 5 minutes.

Prerequisites

  • A Go project with a go.mod and main.go
  • Go 1.21+ on your machine (go version)
  • The paas CLI:
    curl -fsSL https://get.di2amp.com/install.sh | sh
    paas --version
    

If you don't already have a Go project, scaffold one:

mkdir hello-paas && cd hello-paas
go mod init hello-paas
cat > main.go <<'EOF'
package main

import (
    "fmt"
    "net/http"
    "os"
)

func main() {
    port := os.Getenv("PORT")
    if port == "" {
        port = "8080"
    }
    http.HandleFunc("/", func(w http.ResponseWriter, _ *http.Request) {
        fmt.Fprintln(w, "Hello from PaaS Runtime!")
    })
    fmt.Println("listening on :" + port)
    if err := http.ListenAndServe(":"+port, nil); err != nil {
        panic(err)
    }
}
EOF
git init && git add -A && git commit -m "init"

Step 1 — Authenticate

paas login

Verify:

$ paas whoami
octave@paas.local (member of: paas-default)

Step 2 — Create the app

paas apps create hello-paas

Output:

✓ Created app hello-paas
  URL:    https://hello-paas.runtime.di2amp.com
  Region: eu-fr-1
  Plan:   free
  Git:    https://git.di2amp.com/octave/hello-paas.git

Step 3 — Add a Procfile

The Paketo Go buildpack auto-detects main.go and builds a static binary. You only need to declare process types:

# Procfile
web: ./hello-paas

Commit:

git add Procfile && git commit -m "add Procfile"

Step 4 — Push to deploy

git push paas main

You'll see live build logs:

remote: ─────── PaaS Build ───────
remote: → Detected: go (paketo-buildpacks/go)
remote: → Installing Go 1.22.0
remote: → Running: go build -o /workspace/hello-paas .
remote: → Image:    registry.di2amp.com/octave/hello-paas:abc1234
remote: → Image size: 12 MB (static binary, distroless base)
remote: → SBOM:     ✓ generated, 8 packages
remote: → CVE scan: ✓ 0 critical, 0 high
remote:
remote: ─────── PaaS Deploy ───────
remote: → Process types: web
remote: → Replicas:      1/1 ready
remote: → Rollout:       v1 → v2 (canary 10% → 100%)
remote: → Health:        / returns 200 OK
remote: → URL:           https://hello-paas.runtime.di2amp.com
remote:
remote: ✓ Deployed in 28s

The Go buildpack produces compact images (~10–20 MB) thanks to static binaries on a distroless base.

Step 5 — Verify the app is live

$ curl https://hello-paas.runtime.di2amp.com/
Hello from PaaS Runtime!

Dashboard runtime status:

https://ma30.di2amp.com/runtime/dashboard/apps/hello-paas

Next steps

Add a managed PostgreSQL

paas addons create database --type postgres --plan free --name db

DATABASE_URL is injected:

import "database/sql"
import _ "github.com/jackc/pgx/v5/stdlib"

db, err := sql.Open("pgx", os.Getenv("DATABASE_URL"))

Tail logs

paas logs --tail

Custom build flags

The Paketo Go buildpack reads BP_GO_BUILD_FLAGS and BP_GO_TARGETS:

paas config:set BP_GO_BUILD_FLAGS="-ldflags=-s -w -X main.version=$(git rev-parse --short HEAD)"

Multi-binary

Build two binaries (web + worker) by setting:

paas config:set BP_GO_TARGETS="./cmd/web:./cmd/worker"

Then in Procfile:

web: ./web
worker: ./worker

Scale processes

paas ps:scale web=3 worker=2

See also