App service

Go service

Go runtime service for building APIs, workers, and custom applications from source, with optional database, cache, and email links.

This service runs your code: its image is built from a Git repository, and each build is deployed to an app environment.

On Wodby

How Go runs on Wodby

What Wodby sets up for an application that runs on this service. Check it before changing the build, the port or connection settings in the code.

Build and start

The service's Dockerfile copies the repository to /usr/src/app and, when there are .go files at its root:

  1. runs go mod download when go.mod exists;
  2. runs go build -o /home/wodby/go/bin/app .

The container starts that binary as app. So with the service's Dockerfile the main package must be at the root of the repository. A pipeline that passes a Dockerfile from the repository (wodby ci build go -f Dockerfile) uses that file instead; it must still end with a command that starts the server.

  • The application must listen on port 8080, on all interfaces. That is the port of the service's HTTP endpoint. The service sets no PORT variable in a deployed environment: default to 8080 in the code.
  • The service sets no other variable for the application and generates no configuration file.
  • The service declares no volume of its own: files written inside the container are lost when it is replaced.

Linked services

Links to other services reach the application as environment variables. Nothing in the image reads them: the application reads them itself. Do not hardcode hosts or credentials.

LinkVariables
Database (MariaDB, MySQL or PostgreSQL)DB_HOST, DB_PORT, DB_NAME (also DB_DATABASE), DB_USERNAME, DB_PASSWORD, DB_DRIVER (also DB_CONNECTION)
MailSMTP_HOST, SMTP_PORT
Redis or ValkeyREDIS_HOST, REDIS_PORT, REDIS_PASSWORD
OpenTelemetry CollectorOTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_PROTOCOL (http/protobuf), OTEL_EXPORTER_OTLP_HEADERS (the Collector's ingest token)

All links are optional. A variable is present only while its link exists and the linked service is enabled. The mail link carries no credentials. The OpenTelemetry variables are the standard SDK settings: an application or agent that uses an OpenTelemetry SDK exports to the Collector without further configuration; set OTEL_SERVICE_NAME to name the application in traces.

Environment

  • WODBY_HOSTS is a JSON array of the environment's hosts, not a comma-separated string. WODBY_PRIMARY_HOST and WODBY_PRIMARY_URL are the canonical ones for links generated outside a request.
  • WODBY_APP_SERVICE_NAME is this service's host name inside the environment. Other services reach the application at that name on port 8080.
  • WODBY_ENV_TYPE tells a development environment from a production-like one.

In a development workspace

  • The checkout is mounted at /usr/src/app. The application is compiled from it and run, and the checkout is watched: when a file changes, it is compiled again and the application is restarted with the new build, in the same container, usually within a few seconds. Nothing has to be restarted or deployed for a code change. A build that fails leaves the previous build running; the compiler's errors are in the service's logs.
  • Workspace setup resolves dependencies with workspace-go prepare. go.mod is required. Builds use -mod=readonly on a temporary copy of go.mod and go.sum, so the repository's files are never rewritten: a missing requirement or checksum fails the build and must be fixed in the repository with go get or go mod tidy.
  • The package built is .; WORKSPACE_GO_PACKAGE on the service selects another one, such as ./cmd/server.
  • HOST and PORT are set, to 0.0.0.0 and 8080 by default. The application must read them or listen on 8080 anyway.
  • A repository with a go.work file is refused. It needs WORKSPACE_GO_COMMAND on the service, which replaces the start command.
  • The compiled binary is .wodby-workspace/app in the checkout. .wodby-workspace/ is kept out of Git status without touching .gitignore.
  • A change to variables or linked services still needs a deployment of the environment.

Check the result

  • curl -s -o /dev/null -w '%{http_code}' localhost:8080 from the container shows whether the application answers on the expected port.
  • go build ./... && go vet ./... in the checkout shows compile errors at once; the service's logs show them too when a change does not appear.

Overview

Technical profile of Go

The versions are the ones you can select for Go in a stack or an app environment. The service itself is published in revisions, and a stack references a specific revision.

Service type

App service

Versions

1.27, 1.26

Stacks

Stacks that include Go

This public stack includes Go. You can create an app from a public stack as it is, or add the service to a stack of your own.

CI/CD

Build Go from a Git repository

Start from a public boilerplate or connect your own repository. With Wodby CI, a push to the branch that an app environment follows starts a build of Go, and the pipeline deploys it.

Git providers

You connect a repository through an integration with its Git provider.

CI providers

Wodby CI is built in: the pipeline is the file .wodby/pipeline.yml in the repository. For a repository you connect, an external CI provider can run the same steps with Wodby CLI.

Container registries

Built images go to Wodby Registry by default, or to an external registry that you connect as an integration.

Environment variables from integrations

A variable integration stores the credentials of a third-party service once. Attach it to Go and Wodby passes them to the container as environment variables at runtime, not during the image build.

Configuration

Go service configuration

The Go service declares the following. Where a value can be changed, a stack sets it and each app environment can override it.

Technical domains

Wodby gives each public HTTP port a technical domain with a TLS certificate and renews the certificate. A port that the service marks private gets no domain. You can add custom domains.

Service links

Each link is a connection from Go to another service. A stack sets which service a link points to. The cards list the public services that can satisfy each link.