Frameworks
Go
Deploy Go services without a Dockerfile.
Teral recognizes a Go project by its go.mod. It uses the Go version from go.mod, builds one binary and runs it.
Which package is built
In this order:
- the folder in the variable
RAILPACK_GO_BIN, ascmd/<name>, if you set one - the module root, if it has Go files
- the first folder under
cmd/ - for a
go.workworkspace, the first module with amain.go
In a repository with several commands, such as cmd/api and cmd/worker, create one app per command and set RAILPACK_GO_BIN to api or worker in each app's variables.
Listen on the right port
package main
import (
"log"
"net/http"
"os"
)
func main() {
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
http.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("ok"))
})
log.Fatal(http.ListenAndServe(":"+port, nil))
}Listen on ":"+port, not "localhost:"+port, so the gateway can reach the server.
Shut down cleanly
Teral sends SIGTERM and waits 30 seconds before it stops an instance. Use http.Server.Shutdown with signal.NotifyContext(ctx, syscall.SIGTERM) to let requests in progress finish.