Config
Thread-safe configuration management for Go applications with support for multiple sources (files, environment variables, command-line arguments, defaults) and configurable precedence.
Features
- Multiple Sources: Load configuration from defaults, files, environment variables, and CLI arguments
- Configurable Precedence: Control which sources override others
- Type Safety: Struct-based configuration with automatic validation
- Thread-Safe: Concurrent access with read-write locking
- File Watching: Automatic reloading on configuration changes
- Source Tracking: Know exactly where each value came from
- Tag Support: Use
toml,json, oryamlstruct tags
Installation
go get github.com/lixenwraith/config
Quick Start
package main
import (
"log"
"github.com/lixenwraith/config"
)
type AppConfig struct {
Server struct {
Host string `toml:"host"`
Port int `toml:"port"`
} `toml:"server"`
Debug bool `toml:"debug"`
}
func main() {
defaults := &AppConfig{}
defaults.Server.Host = "localhost"
defaults.Server.Port = 8080
cfg, err := config.Quick(defaults, "MYAPP_", "config.toml")
if err != nil {
log.Fatal(err)
}
port, _ := cfg.Get("server.port")
log.Printf("Server port: %d", port.(int64))
}
Documentation
- Quick Start - Get started
- Builder Pattern - Advanced configuration with the builder
- Access Patterns - Getting and setting values
- Command Line - CLI argument handling
- Environment Variables - Environment variable handling
- File Configuration - File formats and loading
- Validation - Validation functions and integration
- Live Reconfiguration - File watching and auto-update on change
- Quick Guide - Quick reference guide
License
BSD-3-Clause
Description
Languages
Go
100%