https://github.com/zoobz-io/fig
Struct tags in, configuration out
https://github.com/zoobz-io/fig
configuration environment-variables go golang secrets struct-tags zoobzio
Last synced: 3 months ago
JSON representation
Struct tags in, configuration out
- Host: GitHub
- URL: https://github.com/zoobz-io/fig
- Owner: zoobz-io
- License: mit
- Created: 2026-01-24T21:01:59.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2026-03-20T03:20:05.000Z (4 months ago)
- Last Synced: 2026-04-04T10:59:32.872Z (3 months ago)
- Topics: configuration, environment-variables, go, golang, secrets, struct-tags, zoobzio
- Language: Go
- Homepage: https://fig.zoobz.io
- Size: 73.2 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
- Security: SECURITY.md
Awesome Lists containing this project
README
# fig
[](https://github.com/zoobz-io/fig/actions/workflows/ci.yml)
[](https://codecov.io/gh/zoobz-io/fig)
[](https://goreportcard.com/report/github.com/zoobz-io/fig)
[](https://github.com/zoobz-io/fig/actions/workflows/codeql.yml)
[](https://pkg.go.dev/github.com/zoobz-io/fig)
[](LICENSE)
[](go.mod)
[](https://github.com/zoobz-io/fig/releases/latest)
Struct tags in, configuration out.
fig loads configuration from environment variables, secret providers, and defaults using Go struct tags. One function call, predictable resolution order.
## Install
```bash
go get github.com/zoobz-io/fig
```
Requires Go 1.24+.
## Quick Start
```go
package main
import (
"log"
"github.com/zoobz-io/fig"
)
type Config struct {
Host string `env:"APP_HOST" default:"localhost"`
Port int `env:"APP_PORT" default:"8080"`
Password string `secret:"db/password"`
Tags []string `env:"APP_TAGS"`
APIKey string `env:"API_KEY" required:"true"`
}
func main() {
var cfg Config
if err := fig.Load(&cfg); err != nil {
log.Fatal(err)
}
// cfg is now populated
}
```
Resolution order: `secret` → `env` → `default` → zero value.
## Capabilities
| Feature | Description |
|---------|-------------|
| Environment variables | `env:"VAR_NAME"` tag |
| Secret providers | `secret:"path/to/secret"` tag with pluggable backends |
| Default values | `default:"value"` tag |
| Required fields | `required:"true"` tag |
| Nested structs | Automatic recursion into embedded structs |
| Validation | Implement `Validator` interface for custom checks |
| Context support | `LoadContext` for secret provider timeouts |
### Supported Types
`string`, `int`, `int8-64`, `uint`, `uint8-64`, `float32`, `float64`, `bool`, `time.Duration`, `[]string` (comma-separated), and any type implementing `encoding.TextUnmarshaler`.
## Secret Providers
Pass a provider implementing `SecretProvider` to load secrets:
```go
type SecretProvider interface {
Get(ctx context.Context, key string) (string, error)
}
```
### Available Providers
Each provider is a separate module — import only what you need:
```bash
# AWS Secrets Manager
go get github.com/zoobz-io/fig/awssm
# GCP Secret Manager
go get github.com/zoobz-io/fig/gcpsm
# HashiCorp Vault
go get github.com/zoobz-io/fig/vault
```
```go
import "github.com/zoobz-io/fig/vault"
p, err := vault.New()
if err != nil {
log.Fatal(err)
}
fig.Load(&cfg, p)
```
Secrets take precedence over environment variables, allowing secure overrides.
## Validation
Implement the `Validator` interface for custom validation after loading:
```go
func (c *Config) Validate() error {
if c.Port <= 0 || c.Port > 65535 {
return errors.New("port must be between 1 and 65535")
}
return nil
}
```
## Why fig?
No config files. No YAML. No JSON. No builder chains. One function, one resolution order, done.
## Contributing
See [CONTRIBUTING.md](CONTRIBUTING.md).
## License
MIT