A minimalist Go backend boilerplate with environment-based configuration and modern project structure.
- 🌍 Environment-based configuration (local, stage, prod)
- 📁 Clean project structure
- ⚙️ Configuration management with Viper
- 🛠️ Makefile for common operations
- 🚀 Quick setup script
- ✅ Test examples included
.
├── bin/ # Compiled binaries
├── cmd/ # Main applications
│ └── main.go # Application entry point
├── config/ # Configuration files
│ ├── local.toml
│ ├── stage.toml
│ └── prod.toml
├── internal/ # Private application code
│ └── config/ # Configuration package
├── pkg/ # Public library code
├── scripts/ # Scripts and tools
├── test/ # Additional test files
├── Makefile
└── README.md
- Go 1.21 or higher
- Make
- Clone the repository:
curl -L https://github.com/devintrap/go-backend-boilerplate/archive/refs/tags/latest.zip -o go-backend-boilerplate.zip
unzip go-backend-boilerplate.zip
mv go-backend-boilerplate-latest your-project-name
cd your-project-name- Initialize your project:
make setup NAME=your-project-name- Run the application:
make run # Run with local config
make run ENV=stage # Run with staging config
make run ENV=prod # Run with production config| Command | Description |
|---|---|
make build |
Build the application |
make run |
Run the application |
make test |
Run tests |
make clean |
Clean build files |
make coverage |
Generate test coverage |
make fmt |
Format code |
make lint |
Run linter |
make setup NAME=<name> |
Initialize project |
Configuration files are in TOML format and located in the config/ directory:
# Example config/local.toml
environment = "local"
[logger]
level = "debug"
format = "console"Set the environment using the ENV variable:
ENV=prod make runRun all tests:
make testGenerate coverage report:
make coverage- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.