Struct Tags In, Configuration Out. One Call. Done.
Load configuration from secrets, environment variables, and defaults using struct tags. No config files, no YAML, no builder patterns — just fig.Load(&cfg).
Get Startedimport "github.com/zoobz-io/fig"
type Config struct {
// Resolution order: secret → env → default → zero value
DBPassword string `secret:"db/pass" env:"DB_PASSWORD" default:"changeme"`
Host string `env:"APP_HOST" default:"localhost"`
Port int `env:"APP_PORT" default:"8080"`
APIKey string `env:"API_KEY" required:"true"`
Timeout time.Duration `env:"TIMEOUT" default:"30s"`
Tags []string `env:"APP_TAGS"`
}
func (c *Config) Validate() error {
if c.Port < 1 || c.Port > 65535 {
return errors.New("port out of range")
}
return nil
}
// One call. Secrets checked first, then env, then defaults.
provider, _ := vault.New()
var cfg Config
fig.Load(&cfg, provider)Why Fig?
Configuration loading that fits in your head.
Deterministic Resolution
Secret → env → default → zero value. Every time, same order, no ambiguity. The most secure source wins.
Declarative Struct Tags
Requirements live with the fields they configure. One place to read, one place to change.
Pluggable Secret Providers
One method interface. Vault, AWS Secrets Manager, GCP Secret Manager — or write your own in five lines.
Validation Hooks
Implement Validate() for cross-field checks, range validation, and business logic after all fields are populated.
Cached Metadata
Struct tag parsing via sentinel is cached after first load. Reflection cost paid once per type, not per call.
Nested Struct Recursion
Embedded structs descended automatically. Build hierarchical configs naturally without extra boilerplate.
Capabilities
Secrets, environment variables, defaults, validation, and type conversion — all through struct tags.
| Feature | Description | Link |
|---|---|---|
| Environment Binding | env:"VAR_NAME" reads from os.Getenv. Empty strings fall through to the next source in the resolution chain. | Quickstart |
| Secret Providers | Minimal interface for pluggable backends. Built-in providers for Vault, AWS Secrets Manager, and GCP Secret Manager. | Secret Providers |
| Default Values | default:"value" provides sensible fallbacks parsed with the same type conversion as env and secrets. | Concepts |
| Required Fields | required:"true" fails Load if no value from any source. Clear error messages with field context. | Troubleshooting |
| Type Conversion | Primitives, durations, slices, pointers, and any encoding.TextUnmarshaler. Extensible via UnmarshalText. | Types |
| Cloud Integrations | Separate modules for HashiCorp Vault KV v2, AWS Secrets Manager, and GCP Secret Manager. | Vault |
Articles
Browse the full fig documentation.