# Deploy Go on forkrail

> Compile Go services and Vercel-style `api/*.go` handlers into static Linux arm64 binaries on Lambda `provided.al2023` with cached modules and tiny cold starts.

- Framework: Go
- Category: APIs & backends
- Status: Production ready
- Adapter / Preset: None (compiled static aarch64 binary)
- Runtime: AWS Lambda provided.al2023 (arm64)
- Detection: go.mod + main.go / cmd/api/main.go or api/*.go
- Memory: 256–640 MB (low footprint)
- URL: https://www.forkrail.com/frameworks/go

## Capabilities

| Capability | Support | Details |
| --- | --- | --- |
| Web server & api/ | Supported | Supports main.go listening on PORT or Vercel api/*.go handlers |
| Static arm64 build | Supported | Built with CGO_ENABLED=0 -ldflags="-s -w" and cached modules |
| Go toolchain detection | Supported | Respects go / toolchain directive in go.mod and vendor/ |
| 10× concurrent HTTP | Supported | Goroutines serve up to 10 concurrent streams per worker |

## 1. Choose a Go server or api/ handlers

forkrail supports both standard Go HTTP servers (at `main.go`, `cmd/api/main.go`, or `cmd/server/main.go`) and Vercel’s per-file `api/*.go` layout (where each file exports one `func(http.ResponseWriter, *http.Request)`):

**main.go (server)**

```go
package main

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

func main() {
	http.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
		w.Header().Set("content-type", "application/json")
		fmt.Fprint(w, `{"ok":true}`)
	})

	port := os.Getenv("PORT")
	if port == "" {
		port = "8080"
	}
	http.ListenAndServe(":"+port, nil)
}
```

**api/hello.go**

```go
package handler

import (
	"fmt"
	"net/http"
)

func Handler(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("content-type", "application/json")
	fmt.Fprint(w, `{"message":"hello from go"}`)
}
```

## 2. Build flags & deploy

The builder compiles with `CGO_ENABLED=0` and `-ldflags="-s -w"` (customize with `GO_BUILD_FLAGS`), uses `-mod=vendor` when a `vendor/` directory exists, and caches Go modules across deployments.

**Deploy Go service**

```bash
forkrail deploy
forkrail deploy --prod
```

> **Logging note for compiled binaries:** Go binaries run without a language runtime shim: `stdout`/`stderr` lines attach to the active request when one request is in flight, while outgoing HTTP calls are not automatically intercepted.

## Related documentation

- [Functions in api/](https://www.forkrail.com/docs/functions.md)
- [Concurrent compute](https://www.forkrail.com/docs/concurrent-compute.md)
- [Function regions](https://www.forkrail.com/docs/function-regions.md)
