A robust, generic configuration manager for Go applications using Viper. This project demonstrates safe management, validation, and restoration of YAML configuration files with automatic backup and corruption recovery.
- Generic config manager for any struct
- Automatic validation of required keys and types
- Periodic config health checks and auto-restore from backup
- Simulated config updates, corruption, and random key injection for testing
- Thread-safe access and updates
- Go 1.18 or newer
Clone the repository:
git clone https://github.com/dimalukas/go-config-manager.git
cd go-config-managerInstall dependencies:
go mod tidyRun the example app:
go run main.goThis will:
- Load and validate
config.yaml - Restore from
config.backup.yamlif the config is invalid or corrupted - Periodically print the config, simulate updates, inject random keys, and corrupt the config file to demonstrate recovery
main.go: Example usage and simulation routinesconfig_manager.go: Generic config manager implementationconfig.yaml: Main configuration fileconfig.backup.yaml: Backup configuration filego.mod,go.sum: Go module files
MIT License