Skip to content

Go

Deploy a Go app on Enzonic

Deploy compiles Go with go build -o .enzonic/bin/server, from the root package or from cmd/<name>/main.go when there is no root main.go, and runs the binary as a server. Go 1.26.0 is used unless go.mod asks for a newer toolchain or GO_VERSION is set.

At a glance

What Enzonic Deploy does with a Go project when you connect it. You can override any of it in the project settings.

Language
Go
Detected from
go.mod at the project root
Build command
go build -o .enzonic/bin/server . (or ./cmd/<name>)
Output
.enzonic/bin/server
Runs as
Server

How it runs

  • Server

    Always: the binary is started with PORT set.

Deploy Go step by step

  1. 1Listen on the PORT environment variable.
  2. 2Keep -o .enzonic/bin/server if you override the build command.
  3. 3Connect the repository and deploy.
main.go
package main

import (
	"fmt"
	"net/http"
	"os"
)

func main() {
	port := os.Getenv("PORT")
	if port == "" {
		port = "8080"
	}
	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		fmt.Fprintln(w, "Hello from Go on Enzonic")
	})
	http.ListenAndServe(":"+port, nil)
}

Connect a database to Go

Create a database on Enzonic Databases (or from the project's settings) and its connection string is added to the project's environment variables. This example uses PostgreSQL.

db.go
pool, err := pgxpool.New(ctx, os.Getenv("DATABASE_URL"))
if err != nil {
	log.Fatal(err)
}
defer pool.Close()

var now time.Time
err = pool.QueryRow(ctx, "select now()").Scan(&now)

Postgres projects get two variables: DATABASE_URL through the connection pooler for the app, and DATABASE_URL_UNPOOLED for migrations.

PostgreSQL on Enzonic DatabasesEvery database engine

Things to know

  • The binary must be static: cgo is off (CGO_ENABLED=0), so packages that need a C library will not build.
  • A custom build command that drops -o .enzonic/bin/server fails with a message saying so.

Plan limits that matter here

From the live plan data. Every plan includes previews for each branch, instant rollback, environment variables and logs.

Plan limits that matter for Go
LimitFreePro
Build minutes3,000/mo, 1 concurrent10,000/mo, 3 concurrent
Servers1 instance, 512 MB, sleeps after 15 min idle3 always-on, 2 GB
Bandwidth150 GB/mo2 TB/mo

Compare every plan

Related guides

Ship your Go project tonight

Connect the repository and the build settings fill themselves in. Free plan, no card.

Start free