Overview
fig loads configuration from environment variables, secret providers, and defaults using Go struct tags.
The Idea
Configuration should be declarative. You define what a field needs—its source, its default, whether it's required—and the library handles the rest. No builder chains, no option structs, no multi-step initialization. One function call, predictable resolution order.
The Implementation
fig provides:
- Struct tag parsing —
env,secret,default, andrequiredtags - Deterministic resolution — secret → env → default → zero value, every time
- Secret provider abstraction — plug in Vault, AWS Secrets Manager, GCP Secret Manager, or your own
- Type conversion — strings, ints, floats, bools, durations, slices, and TextUnmarshaler
- Validation hooks — implement
Validatorfor post-load checks - Nested struct support — automatic recursion into embedded configurations
What It Enables
- Single-source-of-truth configuration structs
- Secure secret injection without environment variable sprawl
- Testable configuration with mock providers
- Consistent loading across services in a microservices architecture
fig integrates with:
- HashiCorp Vault — KV secrets engine
- AWS Secrets Manager — standard AWS credential chain
- GCP Secret Manager — project-scoped secrets
Next Steps
- Quickstart — get productive in minutes
- Concepts — understand resolution order and struct tags
- Reference — full API documentation