# Deploy Go

Any Go module deploys without a framework - plain `net/http` included. Detection reads your `go.mod`, the [generated image](/platform/deployments/builds#dockerfiles-generated-or-your-own) compiles the module and ships the binary, and the default port is `8080`.

## Serve it

Listen on the routed [port](/create/build-settings#port) - `PORT` is set to it:

```go
port := os.Getenv("PORT")
if port == "" {
    port = "8080"
}

http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
    w.Write([]byte("up"))
})
log.Fatal(http.ListenAndServe(":"+port, nil)) // binds 0.0.0.0
```

Log with the standard library or slog to stdout/stderr - both land in [runtime logs](/platform/observability#runtime-logs).

## Configuration and database

Read [environment variables](/platform/environment-variables#build-time-and-runtime) with `os.Getenv` at startup. `DATABASE_URL` from the [Credentials tab](/platform/databases/connect) works with `pgx` and `database/sql`; keep `sslmode=require`.

## Why Go loves this platform

A compiled binary cold-starts in well under a second, so [scale to zero](/create/scaling#min-instances) is close to free - previews and low-traffic APIs cost nothing while idle and answer promptly when hit.

## Related

- [Gin](/platform/frameworks/gin): The framework guides: Gin, Echo, Fiber.
- [Connect an app](/platform/databases/connect): DATABASE_URL, TLS, per-environment databases.
- [Dockerfile](/platform/frameworks/docker): Take over the image for cgo or system packages.
