Prerequisites
- Go 1.21 or higher
- Node.js and npm (for Tailwind CSS)
- Docker and Docker Compose (optional, for containerized development)
- golangci-lint (for linting)
- Air (for hot reload during development)
- templ (for template generation)
Quick Start
Running the Application
- Loads environment variables from
.envfile - Runs the application using
go run ./cmd/web/main.go
Development with Hot Reload
.gofiles.templfiles (template files).htmlfiles
- Test files (
*_test.go) - Generated template files (
*_templ.go) assets/,tmp/,vendor/,testdata/directories
.air.toml):
- Build command:
templ generate && go build -o tmp/main ./cmd/web - Watches for file changes with 0ms delay
- Logs build errors to
build-errors.log - Kills process on port 8080 after rebuild
Build Commands
Build Binary
./bin/web executable.
Output: ./bin/web
Run Built Binary
.env file is configured before running.
Testing
Run All Tests
Run Tests with Coverage
- Runs tests with coverage profiling
- Outputs coverage statistics for each function
View Coverage in Browser
Run Specific Tests
Linting
Run Linter
golangci.toml.
Enabled linters:
- Default: deadcode, errcheck, gosimple, govet, ineffassign, staticcheck, structcheck, typecheck, unused, varcheck
- Code Quality: gocyclo, goconst, revive, unconvert, unparam
- Style: goimports, misspell
- Best Practices: bodyclose, nakedret, tparallel
Fix Auto-Fixable Issues
Lint Specific Packages
Frontend Development
Watch Tailwind CSS
Generate Templates
.templ files and regenerates Go code:
Recommended Development Setup
Run these in separate terminal windows for full hot reload: Terminal 1 - Application:Environment Configuration
Required Environment Variables
Create a.env file in the project root:
Loading Environment Variables
The project usesload_env.sh to source environment variables:
Docker Development
Start All Services
- App (port 8080)
- MongoDB (port 27017)
- Prometheus (port 9090)
- Grafana (port 3000)
Start in Detached Mode
View Logs
Stop Services
Rebuild Containers
Clean Up Volumes
Debugging
Debug with Delve
Enable Debug Logging
SetLOG_LEVEL=debug in your .env file:
Check Port Availability
Continuous Integration
GitHub Actions Workflow
The project includes CI workflows in.github/workflows/.
Typical workflow:
- Checkout code
- Setup Go environment
- Download dependencies
- Run linter
- Run tests with coverage
- Build binary
- Upload artifacts
Running CI Checks Locally
Common Development Tasks
Add New Dependencies
Update Dependencies
Check for Vulnerabilities
Performance Profiling
CPU Profile
Memory Profile
Troubleshooting
Build Fails
Tests Fail
Port Already in Use
MongoDB Connection Issues
Makefile Reference
| Command | Description |
|---|---|
make run | Run application with environment variables |
make air | Run with hot reload using Air |
make build | Build binary to ./bin/web |
make test | Run all tests |
make coverage | Run tests with coverage report |
make lint | Run golangci-lint |
make tailwind | Watch and compile Tailwind CSS |
make templ | Watch and generate templates |