Cascade is a modular configuration loader for Go. It merges configuration from multiple sources in a cascading order: File < Environment < Command-line flags.
- Go 100%
|
|
||
|---|---|---|
| drivers | feat: add pluggable FileDriver interface for custom config formats | |
| examples | fix: update name to lowercase | |
| .gitignore | Initial commit | |
| env.go | Update loadEnv with recursive prefix fix | |
| file.go | feat: add pluggable FileDriver interface for custom config formats | |
| fileDriver.go | feat: add pluggable FileDriver interface for custom config formats | |
| flags.go | fix: change package name from config to cascade | |
| go.mod | fix: update name to lowercase | |
| go.sum | chore: initial commit of Cascade config system | |
| LICENSE | Initial commit | |
| loader.go | fix: ensure struct fields initialized before load to support no-file mode | |
| README.md | feat: update README | |
🌊 Cascade
Go Reference Go Version License: MIT Go Report Card GitHub tag (latest SemVer) Go Module
Cascade is a modular configuration loader for Go. It merges configuration from multiple sources in a cascading order:
File < Environment < Command-line flags
📦 Installation
To add Cascade to your project, use:
go get github.com/Unfield/cascade@latest
Or pin a specific version:
go get github.com/Unfield/cascade@v0.2.4
Then import it in your Go code:
import"github.com/Unfield/cascade"Features
- 📂 Load from YAML or TOML files
- 🌍 Override with environment variables
- 🖥️ Override with command-line flags
- ⚡ Define defaults in your Go structs
- 🔌 Modular & reusable across projects
Quick Example
typeConfigstruct{Serverstruct{Portint`yaml:"port" toml:"port" env:"PORT" flag:"port"`Hoststring`yaml:"host" toml:"host" env:"HOST" flag:"host"`}Securitystruct{EnableTLSbool`yaml:"enable_tls" toml:"enable_tls" env:"ENABLE_TLS" flag:"enable-tls"`CertFilestring`yaml:"cert_file" toml:"cert_file" env:"CERT_FILE" flag:"cert-file"`}}funcmain(){cfg:=Config{}cfg.Server.Port=8080// defaultcfg.Server.Host="0.0.0.0"loader:=cascade.NewLoader(cascade.WithFile("config.yaml"),// or config.tomlcascade.WithEnvPrefix("APP"),cascade.WithFlags(),)iferr:=loader.Load(&cfg);err!=nil{log.Fatal(err)}fmt.Printf("Server running on %s:%d (TLS: %v)\n",cfg.Server.Host,cfg.Server.Port,cfg.Security.EnableTLS)}Priority Order
- Defaults (in Go struct)
- Config file (YAML/TOML)
- Environment variables (
APP_PORT=9000) - Command-line flags (
--port=7000)
License
MIT