A powerful and versatile configuration management package for Go that simplifies handling application settings across different environments and formats.
This README provides a quick overview. For comprehensive guides, tutorials, and API reference:
- Installation Guide - Get started
- User Guide - Learn the features
- API Reference - Complete API docs
- Examples - Real-world patterns
- Troubleshooting - FAQs and solutions
- Easy Integration: Simple and intuitive API
- Flexible Sources: Files, environment variables, Consul, custom sources
- Format Agnostic: JSON, YAML, TOML, and extensible codecs
- Type Casting: Automatic type conversion (bool, int, float, time, duration)
- Hierarchical Merging: Multiple sources merged with precedence
- Struct Binding: Automatic mapping to Go structs
- Built-in Validation: Struct methods, JSON Schemas, custom functions
- Dot Notation: Easy nested configuration access
- Configuration Dumping: Save effective configuration
- Thread-Safe: Safe for concurrent access
- Nil-Safe: Graceful handling of nil instances
go get rivaas.dev/configpackage main
import (
"context"
"log"
"rivaas.dev/config"
)
func main() {
cfg := config.MustNew(
config.WithFile("config.yaml"),
config.WithEnv("APP_"),
)
if err := cfg.Load(context.Background()); err != nil {
log.Fatalf("failed to load config: %v", err)
}
port := cfg.Int("server.port")
host := cfg.StringOr("server.host", "localhost")
log.Printf("Server: %s:%d", host, port)
}- Basic Usage - Loading files, accessing values, error handling
- Environment Variables - 12-factor app configuration
- Struct Binding - Type-safe configuration mapping
- Validation - Ensure configuration correctness
- Multiple Sources - Combine configurations
- Custom Codecs - Support custom formats
Contributions are welcome! Please see the main repository for contribution guidelines.
Apache License 2.0 - see LICENSE for details.