Build And Deploy

Address Configuration

Run the binary with ADDR, PORT, and platform-provided listen addresses.

By Guillermo Alvarez - Published - Updated

Use the built-in order

ListenAndServe reads address settings in this order:

ADDR
PORT
: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.

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.