Go

Built from go.mod, with the Go version it asks for.

On this page

Moorage builds a Go app from its source with the Go version its go.mod asks for, and runs the binary.

The app#

The app listens on 127.0.0.1 and the port in $PORT:

package main

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

func main() {
	http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
		fmt.Fprintln(w, "ok")
	})
	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		fmt.Fprintln(w, "hello from Go")
	})
	http.ListenAndServe("127.0.0.1:"+os.Getenv("PORT"), nil)
}

No manifest is needed: a go.mod is enough. A moorage.toml names the app and a health check:

[app]
name = "hello"

[processes.web]
health = { path = "/healthz" }

Deploy#

See what Moorage will do, then do it:

moor manifest explain
moor deploy

The build is shown as it happens: the Go toolchain is downloaded (once, and verified against its published checksum), the app is built with go build -trimpath -ldflags='-s -w', and the new release takes over once it answers its health check.

How it builds#

[build].command replaces the build entirely, and [build].pre and [build].post run before and after it.

Running it#

[processes]
worker = '"$MOORAGE_BIN/hello" -worker'

Logs, restarts and rollbacks work the same for every app:

moor logs -f
moor rollback

A complete app: the Links example, a link shortener with only the standard library.

Suggest a change to this page