> ## Documentation Index
> Fetch the complete documentation index at: https://docs.slipway.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# Deploy a Go service

> Deploy a compiled Go service with no Dockerfile.

Go builds on slipway in a separate stage and ships a small runtime image, so the deployed
container holds the binary rather than the toolchain.

## Prerequisites

A Go module in a GitHub or GitLab repository, with a `main` package that serves HTTP.

## Configure the app

Bind to `0.0.0.0` on the port you declare. A server bound to `127.0.0.1` cannot be reached
from outside its own container.

```go main.go theme={"system"}
package main

import (
	"net/http"
	"os"
)

func main() {
	port := os.Getenv("PORT")
	if port == "" {
		port = "8080"
	}
	http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("ok"))
	})
	http.ListenAndServe("0.0.0.0:"+port, nil)
}
```

## Add slipway.yaml

```yaml slipway.yaml theme={"system"}
version: 1

services:
  - name: api
    runtime: go
    runtimeVersion: "1.24"
    ports:
      - port: 8080
        public: true
    healthCheckPath: /healthz
    env:
      PORT: "8080"
```

The default build compiles the module's main package. If you set a custom `buildCommand`, it
owns the build stage and must write the binary to `/out/app`:

```yaml slipway.yaml theme={"system"}
    buildCommand: go build -ldflags="-s -w" -o /out/app ./cmd/api
```

## Add a database

```yaml slipway.yaml theme={"system"}
databases:
  - name: db
    engine: postgres
    diskSizeGB: 10

services:
  - name: api
    runtime: go
    env:
      DATABASE_URL: ${service.db.url}
```

## Run migrations before the rollout

```yaml slipway.yaml theme={"system"}
    preDeploy: ["/app", "migrate"]
```

`preDeploy` runs in the freshly built image with the service's resolved environment, and the
deploy proceeds only if it exits 0.

## Add a worker

A Go worker is the same build with no ports:

```yaml slipway.yaml theme={"system"}
  - name: worker
    type: worker
    runtime: go
    runtimeVersion: "1.24"
    buildCommand: go build -o /out/app ./cmd/worker
    env:
      DATABASE_URL: ${service.db.url}
```

## Next steps

> **[CPU and memory](/services/compute)**
>
> A Go service usually runs comfortably at the default allocation.

> **[Service to service](/networking/service-to-service)**
>
> Reach siblings by name.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.