A modern template for Go projects following clean architecture and design pattern best practices. This template provides a robust and scalable foundation for Go application development.
- ✨ Clean and modular architecture
- 🔒 Clear separation of public and private code
- 📝 Ready-to-use logging and metrics setup
- 🔄 CI/CD configuration
- 🧪 Complete testing structure
- 📚 Automatic Swagger documentation
- 🐳 Docker containerization
- 🛠️ Development-friendly Makefile
.
├── cmd/ # Application executables
├── internal/ # Private application code
├── pkg/ # Public libraries
├── configs/ # Configuration files
├── scripts/ # Automation scripts
├── test/ # Integration tests
└── api/ # API documentation
- Go 1.21 or higher
- Docker (optional)
- Make (optional)
- Clone this template:
git clone https://github.com/obrunogonzaga/go-template.git new-project
cd new-project
- Initialize Go module:
go mod init github.com/your-username/new-project
go mod tidy
- Run the application:
make run
make build # Compile the project
make test # Run tests
make lint # Run linter
make swagger # Generate Swagger documentation
make docker # Build Docker image
cmd/
: Contains application entry pointsinternal/
: Application-specific codepkg/
: Libraries that can be used by other projectstest/
: Integration and end-to-end tests
- Use small, focused interfaces
- Follow SOLID principles
- Keep functions short and single-purpose
- Document public APIs
The project uses the following testing tools:
testing
: Standard library for unit teststestify
: Assertions and mocksgomock
: Mock generationhttptest
: HTTP endpoint testing
- All dependencies are verified with
go mod verify
- Static code analysis with
golangci-lint
- Vulnerability scanning with
gosec
The project includes configurations for:
- Docker
- Kubernetes (manifests in
./deploy
) - CI/CD (GitHub Actions)
This project is licensed under the MIT License - see the LICENSE file for details.
- Fork the project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
- Dependency injection
- Interface-based design
- Configuration management
- Error handling
- Middleware support
- Graceful shutdown
- Structured logging
- Metrics and monitoring
- Health checks
- Rate limiting
APP_ENV=development
APP_PORT=8080
DB_HOST=localhost
DB_PORT=5432
The project uses a hierarchical configuration system:
- Default values
- Configuration files
- Environment variables
- Command line flags
- Custom error types
- Error wrapping
- Structured error responses
- Centralized error handling
- Structured logging with levels
- Request ID tracking
- Performance metrics
- Audit logging
Bruno Gonzaga Santos - @brunogsantos - [email protected]
Project Link: https://github.com/obrunogonzaga/go-template