Go

On this page

Short Leash serves Go modules: a folder with a go.mod becomes https://<name>.test. It installs Go 1.24 to 1.27 from go.dev, checking each download against the SHA-256 go.dev lists for it.

How a site runs

Short Leash starts the site on its first request and proxies to the port it gives the program in PORT:

  • With an .air.toml in the project, it runs air, which rebuilds and restarts when you save. Install air yourself; Short Leash doesn't download it.
  • Otherwise it runs go run ., so restart the site with Stop and Start after changing code.

Read the port from the environment and listen on loopback:

addr := "127.0.0.1:" + os.Getenv("PORT")
log.Fatal(http.ListenAndServe(addr, mux))

To run something else, such as a package under cmd/, set the command:

Terminal window
leash run shop "go run ./cmd/server"

Which version a site uses

  1. The version chosen for the site on its Site settings.
  2. Otherwise the lowest version Short Leash offers that satisfies the go line in go.mod, so go 1.25.3 runs on Go 1.25.
  3. Otherwise, when go.mod has no go line, the default on the Runtimes screen, or the newest Go.

The version is downloaded the first time a site needs it. If go.mod asks for a newer Go than Short Leash offers, the site shows an error saying so. The site's Go comes first on the PATH of its background processes, so go and go generate in a process use it too.

Services you add to a Go site with Add to site arrive as URLs, such as DATABASE_URL and REDIS_URL. See Services.