Agent Skills: Golang Configuration

Load and validate application configuration from environment variables and config files. Use when managing Go application config with environment variables or viper. (triggers: configs/**, cmd/**, configuration, env var, viper, koanf)

UncategorizedID: hoangnguyen0403/agent-skills-standard/golang-configuration

Install this agent skill to your local

pnpm dlx add-skill https://github.com/HoangNguyen0403/agent-skills-standard/tree/HEAD/skills/golang/golang-configuration

Skill Files

Browse the full folder contents for golang-configuration.

Download Skill

Loading file tree…

skills/golang/golang-configuration/SKILL.md

Skill Metadata

Name
golang-configuration
Description
"Load and validate application configuration from environment variables and config files. Use when managing Go application config with environment variables or viper. (triggers: configs/**, cmd/**, configuration, env var, viper, koanf)"

Golang Configuration

Priority: P1 (STANDARD)

Principles

  • 12-Factor App: Store config in environment variables.
  • Typed Config: Load config into a struct, validate immediately.
  • Secrets: Never commit secrets. Use env vars or secret managers.
  • No Globals: Return a Config struct and inject it.

Implementation Workflow

  1. Define Config struct — Create a typed struct with all required fields.
  2. Load defaults — Set sensible defaults for non-secret values.
  3. Override from file — Optionally load from YAML/JSON config file.
  4. Override from env — Environment variables take highest priority.
  5. Validate at startup — Crash immediately on missing required config.
  6. Inject via constructor — Pass Config to services; never use global config vars.

See config struct and usage examples

Libraries

  • Standard Lib: os.Getenv for simple apps.
  • Viper: Industry standard for complex configs (env, files, remote).
  • Koanf: Lighter, cleaner alternative to Viper.
  • Caarlos0/env: Strict struct tagging approach.

Anti-Patterns

  • ❌ Hardcoded secrets — load all secrets from env vars or a secret manager
  • ❌ Global config variables — return a typed Config struct and inject via constructors
  • ❌ Starting without validation — crash immediately on missing required env vars

References