Go hosting

Deploy a Go app or API without managing a server

To deploy a Go app on Makofy, commit go.mod and go.sum, make main listen on the PORT environment variable, and connect the repo or run makofy deploy. Makofy builds a static binary with Go 1.23 (CGO_ENABLED=0) into a small Alpine image and runs it with HTTPS. A Go API fits comfortably in the smallest instance: $3.50 a month always on, or $1.50 on Nap.

Last updated · By the Makofy team (Muncar Ventures LLC)

How Makofy builds a Go module

When the repository has a go.mod and no Dockerfile, Makofy uses a two-stage build: it compiles in a golang:1.23-alpine image and copies only the binary into an alpine:3.20 runtime image. The result is a small image with nothing but your program, which also means fast restarts after a deploy or a Nap wake-up.

Build stepWhat happens
Inputsgo.mod and go.sum must both be in the repository
CompileCGO_ENABLED=0 go build -o /app/server ./...
Runtime imagealpine:3.20 with the single binary at /app/server
Start./server, with PORT set (8080 by default)
Time limitThe whole build must finish within 15 minutes

Two things follow from this. First, go.sum must be committed; if your module has no dependencies yet, create an empty one with touch go.sum. Second, the build compiles ./... into one binary, so a repository with several main packages (say cmd/api and cmd/worker) needs a Dockerfile that names the package to build.

A minimal Go HTTP server

package main

import (
	"context"
	"log"
	"net/http"
	"os"
	"os/signal"
	"syscall"
	"time"
)

func main() {
	port := os.Getenv("PORT")
	if port == "" {
		port = "8080"
	}

	mux := http.NewServeMux()
	mux.HandleFunc("GET /healthz", func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("ok"))
	})
	mux.HandleFunc("GET /", func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("hello from Go"))
	})

	srv := &http.Server{Addr: ":" + port, Handler: mux}
	go func() {
		if err := srv.ListenAndServe(); err != http.ErrServerClosed {
			log.Fatal(err)
		}
	}()

	// Finish in-flight requests when a new deploy replaces this one.
	stop := make(chan os.Signal, 1)
	signal.Notify(stop, syscall.SIGTERM, os.Interrupt)
	<-stop
	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
	defer cancel()
	srv.Shutdown(ctx)
}

Deploy it, step by step

  1. Run go mod tidy and commit go.mod and go.sum.
  2. Start the 7-day free trial at makofy.com (card required, no charge until it ends).
  3. Create an app from your GitHub repository and branch. Each push to that branch builds and deploys a new binary.
  4. Or use the CLI: curl -fsSL https://makofy.com/install.sh | sh, makofy login, then makofy deploy from the module root.
  5. Add configuration as environment variables and read them with os.Getenv. They apply on the next deploy.
  6. Open https://<app>--<workspace>.makofy.sh, then set an HTTP health-check path such as /healthz.

When to add a Dockerfile

The detected build covers the common case of one HTTP service with pure-Go dependencies. Add a Dockerfile when you need cgo (for example mattn/go-sqlite3 or other C bindings), a Go version other than 1.23, several binaries in one repo, or extra files such as templates and migrations copied next to the binary. Makofy uses your Dockerfile exactly as written.

FROM golang:1.24-alpine AS build
WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 go build -o /out/api ./cmd/api

FROM alpine:3.20
COPY --from=build /out/api /api
COPY migrations /migrations
CMD ["/api"]

APIs, workers and cron jobs from one repo

Go is often used for more than one kind of process. Each one is its own Makofy service with its own instance type and price, deployed from the same code:

ProcessService typeExampleCheapest option
Public HTTP API or websiteWebmakofy deployNap, $1.50
Internal API other apps callPrivatemakofy deploy --type privateStarter, $3.50
Queue consumerBackground workermakofy deploy --type workerStarter, $3.50
Nightly jobCronmakofy deploy --type cron --schedule "0 3 * * *"Starter, $3.50

Nap works only for web services: it sleeps after 15 idle minutes and wakes on the next request in about 2 to 6 seconds, and a Go binary’s quick startup helps keep that wake-up short. Workers and cron jobs need an always-on type. See background workers and cron jobs.

Postgres, Redis and safe releases

Add Postgres 18 ($3/month) or Redis 8 ($2/month), copy the connection URL from the dashboard into DATABASE_URL or REDIS_URL, and connect with pgx or go-redis. Both are reachable only from apps in your workspace (details). If a new version fails its health check within about two minutes, Makofy redeploys the previous healthy image automatically, and you can roll back to any earlier deploy in one click.

FAQ

Frequently asked questions

How much does it cost to host a Go API on Makofy?

$3.50/month always on with Starter (512 MB, 0.5 vCPU), or $1.50/month on Nap if the API can sleep after 15 idle minutes.

Which Go version does Makofy build with?

Go 1.23 for detected builds. For another version, add a Dockerfile with the golang image you need.

Can I use cgo or SQLite in a Go app on Makofy?

Not with the detected build, which sets CGO_ENABLED=0. Add a Dockerfile that enables cgo and installs the C toolchain.

Which port should a Go server listen on?

Read the PORT environment variable and fall back to 8080; Makofy sets PORT for web and private services.

Why does my Go build fail with a missing go.sum?

The detected build copies go.sum with go.mod. Run go mod tidy and commit it, or create an empty go.sum if there are no dependencies.

Related

Deploy your app in a few minutes.

Connect a GitHub repo or run makofy deploy. Flat price per app, 7-day free trial, card required.

Start free trial