**Tags:** "Hello World" Examples · Golang

# Go Hello World

[Go](https://go.dev) recipe for [Zerops](https://zerops.io) — a minimal HTTP server backed by [PostgreSQL](https://www.postgresql.org), showcasing idempotent database migrations, environment-variable-driven configuration, and the complete set of Zerops infrastructure patterns across six ready-to-deploy environment configurations.

### Available Environments

- [AI Agent](https://app.zerops.io/recipes/go-hello-world.md?environment=ai-agent)
- [Remote (CDE)](https://app.zerops.io/recipes/go-hello-world.md?environment=remote-cde)
- [Local](https://app.zerops.io/recipes/go-hello-world.md?environment=local)
- [Stage](https://app.zerops.io/recipes/go-hello-world.md?environment=stage)
- **Small Production** ← current
- [Highly-available Production](https://app.zerops.io/recipes/go-hello-world.md?environment=highly-available-production)

### Services in this Environment

**Services:**

- **core** (core@1)
  - Containers: 1 × Shared Core, 0.00 GB RAM, 0 GB Disk
- **app** (go@1) :8080
  - Containers: 2 × Shared Core, 0.38 GB RAM, 1 GB Disk
  - Repository: [zerops-recipe-apps/go-hello-world-app](https://github.com/zerops-recipe-apps/go-hello-world-app)
- **db** (postgresql@16) :5432, :6432
  - Containers: 1 × Shared Core, 0.38 GB RAM, 1 GB Disk

**Total Resources:** 4 containers, 1.12 GB RAM, 3 GB Disk

### One-Click Deploy (Import YAML)

Use this YAML with `zcli project import` to deploy this environment:

```yaml
# Small production environment offers a production-ready setup
# optimized for moderate throughput.

project:
  name: go-hello-world-small-prod

services:
  # Production app — Zerops pulls source and zerops.yaml from
  # the 'buildFromGit' repo, using the 'prod' zeropsSetup to
  # compile Go binaries and deploy. 'minContainers: 2' keeps at
  # least two containers running at all times, enabling load
  # distribution and zero-downtime deploys. For custom domains,
  # add a route in the Zerops dashboard after deployment.
  - hostname: app
    type: golang@1.22
    zeropsSetup: prod
    buildFromGit: https://github.com/zerops-recipe-apps/go-hello-world-app
    enableSubdomainAccess: true
    minContainers: 2
    # Zerops auto-scales RAM within these bounds. minFreeRamGB
    # reserves headroom for traffic spikes — without it, the
    # container gets exactly minRam and OOM-kills under load.
    verticalAutoscaling:
      minRam: 0.25
      minFreeRamGB: 0.125

  # PostgreSQL single-node — automatic encrypted backups are on
  # by default. For production traffic, consider HA mode or
  # setting up your own backup strategy. Priority 10 starts it
  # before the app containers, preventing connection errors.
  - hostname: db
    type: postgresql@16
    mode: NON_HA
    priority: 10
    verticalAutoscaling:
      minRam: 0.25
      minFreeRamGB: 0.125

```

---

## Next Steps

After deploying one of the environments and getting to know Zerops, you have two paths to choose from:

1. **Template Flow** — Clone our GitHub repositories and use the whole recipe as a template
2. **Integrate Flow** — If you already have an existing application on a similar stack, integrate the recipe setup with your application

Select a flow: [Template Flow](https://app.zerops.io/recipes/go-hello-world.md?environment=small-production&guideFlow=template) or [Integrate Flow](https://app.zerops.io/recipes/go-hello-world.md?environment=small-production&guideFlow=integrate)

Both flows are shown below:

## How to take over the Small Production environment

### 📦 Clone the template repositories

Fork or clone the following repositories to your local machine or GitHub account:

- [zerops-recipe-apps/go-hello-world-app](https://github.com/zerops-recipe-apps/go-hello-world-app)

### 1. Find your service name

Many commands and configurations need the exact name of your service. You can find it in the Zerops Dashboard.

- Open your project in the Zerops Dashboard.
- In the project overview, find the service you want to manage.
- Use this exact name whenever a command or pipeline configuration asks for `<service-name>`.

<img src="https://storage-prg1.zerops.io/4gfos-storage/copy1_cd2a6044c8.jpg" style="display: block; margin: 0 auto;" alt="Zerops GUI: Locating the Service Name" width="500" />

### 2. Configure deployment pipeline

Go to Service Settings > Pipelines & CI/CD Settings in the Zerops Dashboard and connect your repository.

For production, use a trigger on new tags. This keeps deployments intentional and tied to a specific version. You can also add a regex filter, such as `^v[0-9]+\.[0-9]+\.[0-9]+$`, if you want to allow only semantic version tags.

<img src="https://storage-prg1.zerops.io/4gfos-storage/triggerborder_b865860a89.jpg" style="display: block; margin: 0 auto;" alt="Zerops GUI: Triggers" width="500" />

Alternatively, add `zcli push` to your existing CI/CD pipeline if you want full control over when deployments happen.

Learn more about pipeline triggers: https://docs.zerops.io/features/pipeline

### 3. Deploy to production

Create and push a new Git tag to deploy a specific version of your app:

```bash
git tag -a v1.0.0 -m "Release version 1.0.0"
git push origin v1.0.0
```

> [!TIP]
> Open the pipeline detail in the Zerops Dashboard to check the build progress and verify that all steps finish successfully.

### 4. Configure autoscaling

Review the autoscaling settings for your runtime services and databases in Service Settings > Automatic Scaling Configuration in the Zerops Dashboard.

<img src="https://storage-prg1.zerops.io/4gfos-storage/scaling_ac0880aef5.png" style="display: block; margin: 0 auto;" alt="Zerops GUI: Autoscaling configuration" width="500" />

The most important settings are:

```yaml
verticalAutoscaling:
  minRam: 1
  minFreeRamGB: 0.5
  minFreeRamPercent: 20
```

> [!CAUTION]
> Pay attention to `minFreeRamGB`. This value tells Zerops when to scale RAM vertically. Adjust it based on your app’s real memory needs. RAM scales up immediately, while CPU scales after two consecutive measurements below the threshold.

> [!TIP]
> Run a quick stress test with a tool like hey before real users arrive. This helps you see how your app behaves under load and tune the autoscaling settings.

### 5. Set up your domain

To send real traffic to your app, configure public HTTP access in Service Settings > Public Access & Internal Ports in the Zerops Dashboard.

Add your custom domain and point your DNS records to the Zerops IPs shown in the dashboard:

<img src="https://storage-prg1.zerops.io/4gfos-storage/subdomain_8cafd801e8.jpg" style="display: block; margin: 0 auto;" alt="Zerops GUI: Public access and custom domain" width="500" />

```text
Type   Name          Content          TTL
A      example.com   <zerops-ipv4>    Auto
AAAA   example.com   <project-ipv6>   Auto
```

For wildcard domains, add a CNAME record for SSL validation.

Check the public access documentation: https://docs.zerops.io/features/access

> [!TIP]
> When changing DNS records for production, start with a low TTL value. Make sure SSL certificates are active before you disable the fallback Zerops subdomain.

Once everything works, you can disable the Zerops subdomain so all traffic goes through your custom domain.

---

### 🎉 You are good to go!

Your application is live in production and the core setup is complete.

The following sections are optional. They cover extra production features such as log forwarding, backups, and diagnostic access. You can stop here and come back later when you need them.

---

### 6. Set up log forwarding (Optional)

To send logs to an external service, go to Project Settings > Log Forwarding & Logs Overview in the Zerops Dashboard.

You can forward logs to services like Better Stack, Papertrail, or your own self-hosted solution.

Learn more about log forwarding: https://docs.zerops.io/references/logging

### 7. Configure database backups (Optional)

Manage automated encrypted backups in Service Settings > Backups in the Zerops Dashboard.

By default, backups run daily between 00:00 and 01:00 UTC.

Before a major deployment, create a manual protected backup:

```bash
zcli backup create <db-service> --tags pre-deploy,protected
```

Read the backup documentation for more options: https://docs.zerops.io/features/backup

### 8. Set up diagnostic access (Optional)

Use zCLI and VPN access when you need to inspect or maintain services directly.

For runtime services:

```bash
zcli vpn up
ssh <service-name>.zerops
```

For databases, connect through the VPN to reach the project’s private network, or set up secure direct IP access for your database admin tools.

Check the VPN documentation: https://docs.zerops.io/references/cli/commands#vpn-up

## How to integrate app with Zerops

### 1. Adding `zerops.yaml`

The main application configuration file placed at the root of your repository. It tells Zerops how to build, deploy, and run your application.

```yaml
# Production setup — compile both binaries, deploy minimal
# static artifacts. Development setup — deploy full source
# for SSH-driven development without a pre-build step.
zerops:
  - setup: prod
    build:
      base: go@1.22
      # CGO_ENABLED=0 produces a fully static binary — no C compiler
      # or system libraries linked at runtime. lib/pq is pure Go
      # so this is safe and results in a portable artifact.
      envVariables:
        CGO_ENABLED: "0"
      buildCommands:
        # Download all module dependencies, then build both the
        # app server and the database migration binary.
        - go mod download
        - go build -o app .
        - go build -o migrate ./cmd/migrate
      deployFiles:
        # Deploy only the compiled binaries — no source or toolchain
        # in the runtime image, keeping the artifact minimal.
        - ./app
        - ./migrate
      # cache: true snapshots the global GOMODCACHE (system-level
      # directory), avoiding a full re-download on each build.
      # Not combined with folder-level cache — only one strategy
      # applies per build.
      cache: true

    # Readiness check — verifies each new container responds before
    # the project balancer routes production traffic to it,
    # enabling zero-downtime deploys.
    deploy:
      readinessCheck:
        httpGet:
          port: 8080
          path: /

    run:
      # go@1.22 runtime runs the compiled static binary.
      base: go@1.22
      # Run migration once per deploy via zsc execOnce. Placing it
      # here in initCommands — not buildCommands — ensures the
      # schema and the newly deployed binary are always in sync.
      # execOnce prevents parallel execution across containers.
      initCommands:
        - zsc execOnce ${appVersionId} -- ./migrate
      ports:
        - port: 8080
          httpSupport: true
      envVariables:
        # Zerops generates db_hostname, db_port, db_user, and
        # db_password automatically for the 'db' service.
        # Reference them via ${hostname_key} syntax.
        DB_HOST: ${db_hostname}
        DB_PORT: ${db_port}
        DB_USER: ${db_user}
        DB_PASS: ${db_password}
        # DB_NAME matches the Zerops-generated database name
        # (always the service hostname).
        DB_NAME: db
      start: ./app

  - setup: dev
    # Development workspace — source deployed as-is, developer
    # drives compilation and the server via SSH.
    build:
      base: go@1.22
      buildCommands:
        # Download dependencies into the global GOMODCACHE so the
        # build container image snapshot (cache: true) includes
        # them — avoids a network fetch on every build.
        - go mod download
      deployFiles:
        # Deploy the full source tree so the developer has
        # everything available immediately after SSH.
        - ./
      # cache: true snapshots the entire build container image,
      # preserving the global GOMODCACHE across builds.
      cache: true

    run:
      # go@1.22 provides the full Go toolchain for SSH-driven
      # development — compile, run, and test without additional
      # installation.
      base: go@1.22
      # Migration compiles and runs once per deploy (one-time cost,
      # guarded by execOnce). Database is ready when the developer
      # SSHs in — no manual migration step needed.
      initCommands:
        - zsc execOnce ${appVersionId} -- go run cmd/migrate/main.go
      ports:
        - port: 8080
          httpSupport: true
      envVariables:
        DB_HOST: ${db_hostname}
        DB_PORT: ${db_port}
        DB_USER: ${db_user}
        DB_PASS: ${db_password}
        DB_NAME: db
        # HOME is required — Zerops runtime processes don't inherit
        # it by default, and Go uses it to locate GOPATH and GOCACHE
        # (/home/zerops/go and /home/zerops/.cache/go-build).
        HOME: /home/zerops
      # Zerops starts nothing — container idles, developer runs
      # 'go run .' or 'go build && ./app' via SSH.
      start: zsc noop --silent
```

### 🎯 What's next?

**Deploy other environments** — Ready to scale? Deploy additional environments for different stages of your workflow:

- [AI Agent](https://app.zerops.io/recipes/go-hello-world.md?environment=ai-agent)
- [Remote (CDE)](https://app.zerops.io/recipes/go-hello-world.md?environment=remote-cde)
- [Local](https://app.zerops.io/recipes/go-hello-world.md?environment=local)
- [Stage](https://app.zerops.io/recipes/go-hello-world.md?environment=stage)
- [Highly-available Production](https://app.zerops.io/recipes/go-hello-world.md?environment=highly-available-production)

## Knowledge Base

### Platform Reference

- [Routing & Domains](https://docs.zerops.io/features/access)
- [Scaling](https://docs.zerops.io/features/scaling)
- [Environment Variables](https://docs.zerops.io/features/env-variables)
- [CLI (zcli)](https://docs.zerops.io/references/cli)

### Service Type Reference

**Golang**

- [Build & Deploy](https://docs.zerops.io/go/how-to/build-pipeline)
- [Customize Runtime](https://docs.zerops.io/go/how-to/customize-runtime)

**PostgreSQL**

- [Connect](https://docs.zerops.io/postgresql/how-to/connect)
- [Backup & Restore](https://docs.zerops.io/postgresql/how-to/backup)
- [Manage](https://docs.zerops.io/postgresql/how-to/manage)
- [Scale](https://docs.zerops.io/postgresql/how-to/scale)

---

## Related Recipes

- [Bun Hello World](https://app.zerops.io/recipes/bun-hello-world.md)
- [Zerops showcase](https://app.zerops.io/recipes/zerops-showcase.md)
- [Java Hello World](https://app.zerops.io/recipes/java-hello-world.md)
- [Deno Hello World](https://app.zerops.io/recipes/deno-hello-world.md)

