PreviewDrop for Go

Deploy previews for Go apps

Push a branch, get a live preview URL. PreviewDrop compiles your Go binary, runs it as a long-lived process, and posts the link to the pull request, usually within a couple of minutes.

TL;DR
Connect your repo, push. PreviewDrop detects Go from your go.mod, builds the binary and runs it behind a TLS-terminated subdomain. Your background goroutines, websocket connections and in-memory caches all work because it’s one real process — not a per-request serverless function with a 10-second ceiling.

What the build needs to do

You don't write this. PreviewDrop detects Gofrom your repo and builds the container for you — a Dockerfile in your repo is not used. The reference below shows the install, build and start steps a working Go image needs. If detection gets one wrong, set the matching Install, Build or Start command in Project Settings. Your app must listen on $PORT.

Reference (not read by PreviewDrop)
FROM golang:1.23-alpine AS build WORKDIR /src COPY go.mod go.sum ./ RUN go mod download COPY . . # Static binary so a distroless/scratch runtime works RUN CGO_ENABLED=0 go build -o /app . FROM gcr.io/distroless/static-debian12 COPY --from=build /app /app EXPOSE 8080 ENV PORT=8080 CMD ["/app"]

Environment variables

Set these in the Variables tab of your PreviewDrop project. They're encrypted at rest and injected into every preview container at start.

VariableExample valueNote
PORT8080PreviewDrop injects this. Read it in main() and listen on it.
DATABASE_URLpostgres://user:pass@host:5432/dbPoint at a shared dev DB, or omit for stateless / in-memory previews.
GIN_MODEreleaseIf you use Gin — silences debug logging. Equivalent flags exist for Echo / Fiber.

Common gotchas

Listen on 0.0.0.0 and read PORT from the environment

Bind with http.ListenAndServe(":"+os.Getenv("PORT"), mux). A colon-prefixed address binds all interfaces; binding to 127.0.0.1 makes the container unreachable from the proxy and the preview will 502.

CGO_ENABLED=0 for a static binary

The reference build above uses a distroless static runtime with no libc, so it builds with CGO_ENABLED=0 and the binary is fully static. Prefer pure-Go drivers where you can — a cgo dependency (e.g. a SQLite driver) needs a C toolchain at build time and libc at runtime.

Point the build at the right main package

go build -o /app . assumes package main is at the repo root. If your entrypoint lives under cmd/server, set the Build command in Project Settings to build ./cmd/server instead.

Read config from environment variables

Set database URLs, API keys and mode flags as project variables in PreviewDrop and read them with os.Getenv at startup, rather than baking them into the binary or a config file checked into the repo.

Why not Vercel or Netlify?

Vercel supports Go only as serverless functions — one exported handler per file, a hard request timeout, and no process that outlives a request. A real Go HTTP server with background goroutines, websockets, ticker loops and shared in-memory state simply doesn’t fit that model. PreviewDrop runs your compiled binary as a persistent process — identical to how it runs in production.

Preview your Go app in 5 minutes

Connect a repo, push a branch, get a URL. No credit card, no trial clock.

Start free