β¨ Features
- π© Advanced Build System: Powered by
Taskfile for streamlined, repeatable builds and development tasks.
- β‘ Hot-Reloading: Uses
air for live-reloading during development, boosting productivity.
- π§ͺ Comprehensive Testing: Integrated with
gotestsum for beautiful, readable test outputs. Supports unit, integration, and benchmark tests.
- π Advanced Code Coverage:
- Standard HTML reports.
- Enhanced function-level reports via
gocov and gocov-html.
- Interactive visual treemaps via
go-cover-treemap.
- π Code Quality Assurance:
- Linting with
golangci-lint using a comprehensive ruleset.
- Formatting with
gofmt.
- Static analysis with
go vet.
- βοΈ Configuration Management: Flexible configuration loading for different environments using
viper.
- π Optimized Production Builds:
- Cross-platform compilation for Linux, macOS, and Windows.
- Aggressive size reduction using
ldflags (-s -w).
- UPX compression for ultra-small binaries (up to 85% size reduction).
- π³ Docker Ready: Multi-stage
Dockerfile for small, secure production images.
- ποΈ Centralized Binary Naming: Easily manage binary names from a single variable in the
Taskfile.
- π Self-Documenting: Includes a
task help command for a detailed overview of all available tasks.
π οΈ Key Dependencies
Core Libraries
ποΈ Project Structure
scaffold/
βββ build/ # Build artifacts (binaries)
βββ cmd/
β βββ server/ # Main application entrypoint
βββ configs/ # Configuration files (local.yml, prod.yml)
βββ internal/ # Internal application code
β βββ handler/
β βββ middleware/
β βββ model/
β βββ repository/
β βββ service/
βββ pkg/ # Public packages
β βββ config/
β βββ helper/
β βββ http/
β βββ log/
βββ .air.toml # Configuration for hot-reloading (air)
βββ .golangci.yml # Configuration for golangci-lint
βββ Dockerfile # Multi-stage Dockerfile
βββ go.mod
βββ go.sum
βββ Taskfile.yml # The heart of the build system
π Getting Started
Prerequisites
- Go (version 1.22+ recommended)
- Task
- Docker (for containerized builds)
- UPX (optional, for binary compression)
Installation
-
Clone the repository:
git clone https://github.com/thedatageek/scaffold.git
cd scaffold
-
Install dependencies:
The project uses Go Modules. The required tools and dependencies are installed automatically when you run a task for the first time. To install them manually:
task deps
π Usage: Available Tasks
This project uses Taskfile.yml as a modern alternative to Makefile. All commands are managed through task.
Run task --list for a quick overview or task help for detailed descriptions.
π¦ Build Tasks
| Command |
Description |
task build |
Build a development binary with debug symbols and race detection. |
task build:release:linux |
Build an optimized, compressed release binary for Linux. |
task build:release:darwin |
Build an optimized, compressed release binary for macOS. |
task build:release:windows |
Build an optimized, compressed release binary for Windows. |
task build:release:all |
Build release binaries for all platforms. |
π Development Tasks
| Command |
Description |
task run |
Run the application using configs/local.yml. |
task run:prod |
Run the application using configs/prod.yml. |
task dev |
Run with hot-reloading using air. |
π§ͺ Test Tasks
| Command |
Description |
task test |
Run all tests using gotestsum. |
task test:unit |
Run only unit tests. |
task test:integration |
Run only integration tests. |
task test:race |
Run tests with the race detector enabled. |
task test:benchmark |
Run benchmark tests. |
task test:coverage |
Generate a standard HTML coverage report. |
task test:coverage:open |
Generate comprehensive coverage reports (HTML, gocov, treemap) and open in browser. |
π Code Quality Tasks
| Command |
Description |
task lint |
Run golangci-lint to find code issues. |
task fmt |
Format all Go source files with gofmt. |
task vet |
Run go vet to analyze source code. |
task check |
Run all quality checks (fmt, vet, lint). |
π³ Docker Tasks
| Command |
Description |
task docker:build |
Build a production-ready Docker image. |
task docker:run |
Run the application in a Docker container. |
βοΈ Utility Tasks
| Command |
Description |
task deps |
Download and tidy Go module dependencies. |
task deps:update |
Update all dependencies to the latest versions. |
task clean |
Clean all build artifacts and caches. |
task config:validate |
Validate all .yml files in the configs directory. |
task help |
Show detailed help for all tasks. |
βοΈ Configuration
Application configuration is managed by viper and loaded from the configs/ directory.
configs/local.yml: Used for local development (task run, task dev).
configs/prod.yml: Used for production runs (task run:prod).
You can specify a configuration file using the --config flag:
go run ./cmd/server --config=configs/local.yml
The system also supports a --validate-config flag to check if a configuration file is valid without running the server, used in the task config:validate task.
π¦ Build & Deployment
Development Build
For a quick debug build with race detection enabled:
task build
This creates a binary at build/debug/scaffold-debug.
Production Release Builds
To create highly optimized and compressed binaries for distribution:
task build:release:all
This generates binaries for Linux, macOS, and Windows in their respective build/ subdirectories (e.g., build/linux/scaffold-amd64-linux).
Optimization Highlights:
- Stripped Symbols (
-s -w): Removes debug information to reduce size.
- Static Linking: Creates self-contained binaries where possible.
- UPX Compression: Further compresses the binary, often resulting in an 80-85% size reduction. A 10MB binary can become ~1.5MB.
π¬ Testing and Coverage
This boilerplate offers a rich testing and coverage experience.
To run all tests:
task test
To generate and view the full suite of coverage reports:
task test:coverage:open
This command:
- Runs tests and generates coverage data.
- Creates three different reports in the
reports/ directory:
coverage.html (standard)
coverage-enhanced.html (detailed)
coverage-treemap.svg (visual)
- Starts a local web server on port
8080.
- Opens your browser to view the reports.
π€ Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository.
- 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.
π License
This project is licensed under the MIT License - see the LICENSE file for details.