Prerequisites
- Go 1.22 or later installed
- Basic familiarity with Go modules
Step-by-step guide
Create your application config struct
Create a
main.go file and define your configuration struct:main.go
Load configuration and initialize logging
Add the main function to load configuration and set up logging:
main.go
Configuration precedence
Salt uses the following configuration precedence (highest to lowest):- Command-line flags (if
WithFlags()is used) - Environment variables (with the specified prefix)
- Configuration file (YAML/JSON)
- Default values (from struct tags)
- Use sensible defaults for development
- Override with config files for different environments
- Override specific values with environment variables in production
- Override everything with command-line flags for testing
Next steps
Now that you have a basic Salt application running, explore more features:Configuration Package
Learn about advanced configuration features like dynamic flag binding and validation
Logging Package
Explore structured logging with Logrus and Zap
Database Package
Add database connectivity with connection pooling and migrations
CLI Utilities
Build powerful CLI tools with commander, printer, and prompter
Complete example
Here’s the complete working example:View complete main.go
View complete main.go
View complete config.yaml
View complete config.yaml