.env · generator · Go

Go .env Generator

Go apps typically use godotenv (joho/godotenv) or envconfig (kelseyhightower/envconfig) to load .env. This generator produces a Go-idiomatic .env with PORT, DATABASE_URL, JWT_SECRET, and CORS origins.

.env for Go · 6 keys
Customize →
APP_ENV=development
PORT=8080
DATABASE_URL=postgres://user:pass@localhost:5432/app?sslmode=disable
JWT_SECRET=FrhDnlB8Z1auP4d88KI5QX4KB6lDcEqpZcDwFoZZmYB1meNt
LOG_LEVEL=info
CORS_ORIGINS=http://localhost:3000

Secrets regenerate on every page load. Want to combine stacks (e.g., Next.js + Stripe + Supabase)? Use the full generator.

How to use this .env in Go

  1. 1.Save as .env in the project root.
  2. 2.Add godotenv: go get github.com/joho/godotenv.
  3. 3.Call godotenv.Load() at the very top of main(), before any other config reads.
  4. 4.Access via os.Getenv("KEY") or decode into a struct with envconfig.Process().

Gotchas

  • Call godotenv.Load() before any package-level init() that reads env — init order bites here.
  • In production, most Go hosts inject env via the kernel — don't ship .env to prod.
  • sslmode=disable is fine for dev Postgres but a hard no in prod — switch to require or verify-full.

Common keys explained

APP_ENV

development | staging | production.

PORT

HTTP bind port. 8080 is the Go default.

DATABASE_URL

Postgres DSN. Use sslmode=disable locally only.

JWT_SECRET

HMAC key for signing JWTs. Generate, don't type.

LOG_LEVEL

One of trace | debug | info | warn | error. Matches zerolog/slog.

CORS_ORIGINS

Comma-separated origins for the CORS middleware.

Related tools

Other stacks