App

Configuration And Secrets

Use environment variables and development secrets without coupling the app to a deployment platform.

By Guillermo Alvarez - Published - Updated

Configure the listen address

GoLazy reads ADDR, then PORT, then defaults to :3000:

ADDR=127.0.0.1:4000 lazy
PORT=4000 ./sample-app

Use ADDR when you want to control the host and port together. Use PORT when the deployment platform supplies only a port.

Read app-owned secrets

Application code reads ordinary environment variables:

func secureCookieKey() string {
    if key := os.Getenv("SECURE_COOKIE_KEY"); key != "" {
        return key
    }
    return developmentSecureCookieKey
}

The framework does not require a specific secret manager. Production deployments should provide real values through the platform or secret store.

Keep development examples local

The sample app includes development tooling and example secrets:

mise.toml
secrets/development.env

Those files are for local commands. Do not depend on mise in production; the production process should receive environment variables from its runtime environment.

Pass configuration into services

Prefer explicit service constructors when configuration affects behavior:

type MailerConfig struct {
    From string
}

func NewMailerFromEnv() (*Mailer, error) {
    return NewMailer(MailerConfig{
        From: os.Getenv("MAIL_FROM"),
    })
}

Initialize the service once in Context, then expose it through typed context helpers.