envconfig

A lightweight, dependency-free Go library that populates typed structs from environment variables using reflection and struct tags.

Library
Go
vv1.4.0
5,468stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
45/100Fair
Development Activity0
Maintenance20
Community60
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
63/100Good
Architecture65
Code Quality72
Innovation78
Learning Curve35

envconfig is a small, dependency-free Go library from Kelsey Hightower for loading application configuration out of environment variables into a plain struct. Instead of hand-writing os.Getenv calls and manual type conversions, you define a Specification struct with typed fields, call envconfig.Process with a prefix, and reflection walks the struct filling in each field from PREFIX_FIELDNAME (or a custom key via the envconfig tag).

It supports defaults, required fields, automatic camelCase-to-SNAKE_CASE splitting, embedded structs, slices and maps parsed from comma/colon-delimited strings, and custom decoding via the Decoder, Setter (flag.Value-compatible), TextUnmarshaler, and BinaryUnmarshaler interfaces. A companion Usage/Usagef API can print a self-documenting table of every configuration variable the program accepts, generated straight from the struct definition.

What You Get

  • A single Process(prefix, &spec) call that maps environment variables to struct fields by name
  • Struct tag support for default, required, envconfig (custom key), split_words, and ignored
  • Built-in parsing for strings, all int/uint/float sizes, bool, time.Duration, slices, and maps
  • Pluggable custom decoding via Decoder, Setter, TextUnmarshaler, and BinaryUnmarshaler interfaces
  • A Usage/Usagef helper that renders a formatted table of every recognized environment variable

Common Use Cases

  • Loading twelve-factor app configuration (ports, timeouts, feature flags) at process startup
  • Generating self-documenting help output listing every environment variable a service reads
  • Enforcing required configuration values fail fast with required:“true” before a service starts serving traffic
  • Decoding structured values like IP addresses or custom JSON blobs from a single environment variable via a custom Decoder

Under The Hood

Architecture The package centers on gatherInfo in envconfig.go, which walks a struct via reflect, resolving each field’s environment-variable key from its tags (or a split_words-derived name) and recursing into embedded/nested structs; Process then iterates that gathered varInfo list, looks up each key with a build-tag-selected lookupEnv (env_os.go uses os.LookupEnv on modern Go, env_syscall.go falls back to syscall.Getenv for pre-1.5 compatibility — a legacy artifact retained from the package’s early-2010s origins), applies defaults/required checks, and dispatches to processField’s type switch for the actual conversion. usage.go is a separate, self-contained file that reuses gatherInfo to drive a text/template-based table renderer, keeping documentation generation decoupled from parsing. The design is a flat, single-package module with no internal layering beyond this — appropriate for its narrow scope.

Tech Stack Pure Go standard library: reflect and regexp for the tag-driven field walk, encoding (TextUnmarshaler/BinaryUnmarshaler) and a local Decoder/Setter pair for extensibility, strconv and time for scalar conversions, and text/template/text/tabwriter for the usage table. There are zero third-party runtime dependencies. go.mod declares go 1.20 with no other entries. CI is a single GitHub Actions workflow (.github/workflows/go.yml) that runs go build ./... and go test -v ./... against Go 1.20 on push and pull requests to master — no linter step is configured.

Code Quality Test coverage is extensive relative to the package’s size: roughly 40 test functions spread across envconfig_test.go, usage_test.go, and a build-tag-gated envconfig_1.8_test.go, all written against the standard testing package with direct t.Errorf assertions (no third-party assertion library). Error handling is explicit and typed — a dedicated ParseError struct wraps key/field/type/value context around every conversion failure, and ErrInvalidSpecification is a clear sentinel for misuse. Naming is consistent and idiomatic Go throughout. There is no .golangci.yml or explicit lint step in CI, so style enforcement relies on convention rather than tooling.

API Design The public surface is deliberately small: a single Process(prefix, &spec) call covers the common case, and the zero-config default (upper-snake-cased field name) means most structs need no struct tags at all. Opt-in specialization — default, required, envconfig, split_words, ignored — keeps the common path boilerplate-free while still supporting overrides for edge cases like acronym-heavy field names. Custom decoding is pluggable through four well-established interface shapes (a local Decoder, flag.Value-compatible Setter, and the two standard-library encoding unmarshaler interfaces) rather than inventing a bespoke hook, so existing types often work with no changes. The Usage/Usagef/Usaget family is a genuinely useful extra: free, always-in-sync --help-style documentation generated from the same struct that drives parsing, which most comparable env-to-struct libraries do not offer.

Used by 11 apps in this directory

Rust
65%
Apache 2.0

agentgateway

AI Development · Developer Tools

4,640

An open source AI-native proxy that secures, observes, and governs agent-to-LLM, agent-to-tool, and agent-to-agent communication through MCP, A2A, and unified LLM routing.

View details
87
Repo Health
82
Technical
71
Dependency
Built with
Rust65%
Go23%
Updated 3 days ago
Go
55%
Apache 2.0

Authgear

Authentication

2,014

Open-source, self-hostable authentication platform with passkeys, biometric login, SSO, MFA, and GraphQL admin API — a full Auth0/Clerk/Firebase alternative for SaaS and mobile apps.

View details
88
Repo Health
81
Technical
69
Dependency
Built with
Go55%
HTML25%
TypeScript17%
Updated 4 days ago
Go
73%
Other

Convoy

Developer Tools · Devops

2,862

Convoy is an open-source, cloud-native webhooks gateway that ingests events over HTTP or straight from Kafka, SQS, Google Pub/Sub, and RabbitMQ, then reliably delivers them to subscriber endpoints with signed payloads, automatic retries, circuit breaking, and JavaScript-based transformations.

View details
89
Repo Health
81
Technical
66
Dependency
Built with
Go73%
TypeScript13%
HTML12%
Updated yesterday
Go
75%
MIT

Digger

Devops · Automation · Developer Tools

5,033

Run Terraform and OpenTofu natively inside your existing CI pipeline — no separate runners, no third-party secrets, no extra compute costs.

View details
71
Repo Health
73
Technical
67
Dependency
Built with
Go75%
TypeScript15%
Updated 2 weeks ago
Go
51%
MIT

Fathom Lite

Analytics

8,013

A simple, self-hosted website analytics tool built with Go and Preact that lets you understand your traffic without handing data to third parties.

View details
48
Repo Health
67
Technical
68
Dependency
Built with
Go51%
JavaScript31%
CSS15%
Updated 5 months ago
Go
65%
Other

Hanko

Security · Authentication

9,016

Open source, self-hostable authentication platform with passkeys, SAML SSO, and OAuth — the privacy-first alternative to Auth0 and Clerk.

View details
89
Repo Health
81
Technical
69
Dependency
Built with
Go65%
TypeScript30%
Updated 2 days ago
Go
61%
Apache 2.0

Harness Open Source

Developer Tools · Devops · Code Editors

38,169

A unified open source DevOps platform combining Git hosting, CI/CD pipelines, cloud development environments, and artifact registries in a single self-hosted system.

View details
89
Repo Health
79
Technical
64
Dependency
Built with
Go61%
TypeScript34%
Updated 2 days ago
TypeScript
61%
EPL-2.0

Huly Platform

Project Management · Team Chat · Collaboration

27,492

Open-source all-in-one workspace that replaces Linear, Jira, Slack, and Notion for product and engineering teams.

View details
90
Repo Health
86
Technical
64
Dependency
Built with
TypeScript61%
Svelte34%
Updated 3 days ago
Go
97%
Apache 2.0

infracost

Devops · Developer Tools

12,499

Infracost shows cloud cost estimates for Terraform, CloudFormation, and AWS CDK before you deploy — in your terminal, editor, AI coding agent, and pull requests.

View details
79
Repo Health
78
Technical
68
Dependency
Built with
Go97%
Updated 6 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search