Skillshub golang-configuration

Standards for application configuration using environment variables and libraries. Use when managing Go application config with environment variables or viper. (triggers: configs/**, cmd/**, configuration, env var, viper, koanf)

install
source · Clone the upstream repo
git clone https://github.com/ComeOnOliver/skillshub
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ComeOnOliver/skillshub "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/HoangNguyen0403/agent-skills-standard/golang-configuration" ~/.claude/skills/comeonoliver-skillshub-golang-configuration && rm -rf "$T"
manifest: skills/HoangNguyen0403/agent-skills-standard/golang-configuration/SKILL.md
source content

Golang Configuration Standards

Priority: P1 (STANDARD)

Principles

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

Libraries

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

Pattern

  1. Define
    Config
    struct.
  2. Load from defaults.
  3. Override from file (optional).
  4. Override from Env (priority).
  5. Validate.

References

Anti-Patterns

  • No hardcoded secrets: Load all secrets from env vars or a secret manager.
  • No global config vars: Return a typed Config struct and inject it via constructors.
  • No startup without validation: Crash immediately on missing required env vars.