Deploy Go

Leash detects Go apps by the presence of go.mod. Just deploy from your project directory.

Detection

If your project root contains a go.mod file, Leash automatically builds and deploys it as a Go application.

Example App

main.go
package main
import (
"encoding/json"
"fmt"
"net/http"
"os"
)
func main() {
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello from Leash!")
})
http.HandleFunc("/api/health", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(map[string]string{"status": "ok"})
})
fmt.Printf("Server running on port %s\n", port)
http.ListenAndServe(":"+port, nil)
}

go.mod

go.mod
module my-go-service
go 1.22

Deploy

Terminal

$ cd my-go-service

$ leash deploy

✓ Detected Go

✓ Image built and pushed

✓ Deployed successfully!

→ https://my-go-service-arvin.un.leash.build