1
0
Fork
You've already forked cascade
0
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%
2025年10月20日 11:57:39 +02:00
drivers feat: add pluggable FileDriver interface for custom config formats 2025年09月07日 17:19:12 +02:00
examples fix: update name to lowercase 2025年09月07日 16:58:53 +02:00
.gitignore Initial commit 2025年09月07日 16:40:50 +02:00
env.go Update loadEnv with recursive prefix fix 2025年10月20日 07:20:59 +02:00
file.go feat: add pluggable FileDriver interface for custom config formats 2025年09月07日 17:19:12 +02:00
fileDriver.go feat: add pluggable FileDriver interface for custom config formats 2025年09月07日 17:19:12 +02:00
flags.go fix: change package name from config to cascade 2025年09月07日 17:01:11 +02:00
go.mod fix: update name to lowercase 2025年09月07日 16:58:53 +02:00
go.sum chore: initial commit of Cascade config system 2025年09月07日 16:49:21 +02:00
LICENSE Initial commit 2025年09月07日 16:40:50 +02:00
loader.go fix: ensure struct fields initialized before load to support no-file mode 2025年10月20日 07:44:58 +02:00
README.md feat: update README 2025年10月20日 11:57:39 +02:00

🌊 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

  1. Defaults (in Go struct)
  2. Config file (YAML/TOML)
  3. Environment variables (APP_PORT=9000)
  4. Command-line flags (--port=7000)

License

MIT