Skip to content
Firefly Plus
Docs menu
Docs / Start

Example: Go

A small Go web app, a Dockerfile that builds a tiny image, and how to deploy it.

A web app in Go, with only the standard library. It answers on the port in PORT, which we set for each instance.

The app

main.go:

// A minimal web app: it answers on the port in PORT, which the platform sets.
package main

import (
	"fmt"
	"log"
	"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")
	})
	log.Printf("listening on %s", port)
	log.Fatal(http.ListenAndServe(":"+port, nil))
}

go.mod:

module example.com/hello

go 1.25

The Dockerfile

FROM golang:1.25-alpine AS build
WORKDIR /src
COPY go.mod ./
COPY . .
RUN CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o /hello .

FROM gcr.io/distroless/static-debian12:nonroot
COPY --from=build /hello /hello
CMD ["/hello"]

It builds a static binary and copies it into a minimal image that runs as a user without privileges, so the image you deploy is a few megabytes.

Deploy it

You can deploy it two ways.

From GitHub

  1. Put these files in a repository on GitHub.
  2. In the dashboard, choose Create app, name it, and choose GitHub repository as its source. Pick the repository and branch.
  3. Keep the web process’s Port at 8080, or any port you like: your app reads it from PORT.
  4. Choose Create app. It builds your Dockerfile and deploys; every push to the branch does it again.

From an image you build

  1. Build the image for 64-bit Linux, and push it to a registry you use, such as Docker Hub or GitHub’s:

    docker build --platform linux/amd64 -t ghcr.io/you/hello-go:1 .
    docker push ghcr.io/you/hello-go:1
  2. Choose Create app, name it, choose Container image, and enter the image in Image.

  3. Keep the web process’s Port at 8080, and choose Create app.

Check it

Once its deploy succeeds, open https://hello-go.fireflyplus.site. It says:

Hello from Go

Something unclear? Email support@firefly.plus.