On this page

Go

Guara Cloud fully supports Go applications. Go’s compiled nature makes it ideal for containerized deployments — producing small, fast, self-contained binaries.

Supported versions

The following Go versions are auto-detected:

  • Go 1.21
  • Go 1.22
  • Go 1.23

The version is auto-detected from the go directive in your go.mod file.

// go.mod
module my-app

go 1.23

Deploy with Dockerfile

A multi-stage build is the recommended approach for Go applications. It compiles your binary in a full Go environment, then copies only the binary into a minimal runtime image.

FROM golang:1.23-alpine AS build

WORKDIR /app

COPY go.mod go.sum ./
RUN go mod download

COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -o server .

FROM alpine:3.19

WORKDIR /app
COPY --from=build /app/server .

EXPOSE 3000

CMD ["./server"]

Deploy with Buildpack

If your repository does not contain a Dockerfile, Guara Cloud automatically detects your Go project by the presence of a go.mod or go.work file.

The auto-detection will:

  1. Detect the Go version from go.mod
  2. Download dependencies with go mod download
  3. Build your application (Go workspaces via go.work are supported)
  4. Run the compiled binary directly

CGO support is available when your application requires C dependencies.

Port configuration

Your application must listen on the port configured in your service settings. The default is 3000, but you can change it at any time to match your application.

port := os.Getenv("PORT")
if port == "" {
    port = "3000"
}
http.ListenAndServe(":"+port, nil)

Example project structure

my-go-app/
  go.mod
  go.sum
  main.go
  internal/
    handlers/
    models/
  Dockerfile          # optional — omit to use Buildpack

Environment variables

These environment variables are commonly used with Go deployments:

VariableRecommended valueDescription
PORTSet by platformThe port your application must listen on
CGO_ENABLED0Produces a statically linked binary (no C deps)
GOOSlinuxTarget operating system for cross-compilation

Common pitfalls