Build And Deploy
Address Configuration
Run the binary with ADDR, PORT, and platform-provided listen addresses.
Use the built-in order
ListenAndServe reads address settings in this order:
ADDR
PORT
127.0.0.1:3000
ADDR can be a full listen address:
ADDR=127.0.0.1:4000 ./app
PORT is useful on platforms that provide only a port:
PORT=8080 ./app
Bind for production
Use a public interface inside containers or platform runtimes:
ADDR=0.0.0.0:8080 ./app
TLS termination, routing, and process supervision usually belong to the deployment platform.
Split operational traffic
Set CONTROL_PLANE_ADDR when liveness, readiness, metrics, or pprof endpoints
should live on a separate address:
ADDR=0.0.0.0:8080 CONTROL_PLANE_ADDR=127.0.0.1:9090 ./app
When CONTROL_PLANE_ADDR is the same as ADDR, PORT, or the default
127.0.0.1:3000, GoLazy mounts the control plane into the app server instead
of binding the same address twice. Read
Control Plane for the endpoint and config
details.
Keep main small
Application entrypoints can rely on ListenAndServe:
func main() {
if err := appinit.App().ListenAndServe(); err != nil {
log.Fatal(err)
}
}
When you need a custom http.Server, use appinit.App() as the handler and
set the server address yourself.