11 · Dev Environment
First-run checklist — from clone to running API
Prerequisites
- Go 1.21+ —
go versionto verify - Docker Desktop (for postgres + redis via docker-compose)
make— available by default on macOS/Linux
First Run — lp-coupon-api
# 1. Clone
git clone <repo-url> lp-coupon-api
cd lp-coupon-api
# 2. Copy env
cp .env.example .env
# Edit .env — set DB_PASSWORD, ALLOWED_CLIENTS (see .env.example comments)
# 3. Start dependencies (PostgreSQL + Redis)
make compose-up
# Wait ~10 seconds for postgres to be healthy
# 4. Run migrations
cd scripts/migration
./migrate.sh up
cd ../..
# 5. Start the API
make run
# Output: "Starting HTTP server" on port 8080
# 6. Verify
curl http://localhost:8080/coupon/api/health
Make Commands Reference
| Command | What it does |
|---|---|
make run | Start the API locally (go run main.go) |
make build | Compile binary to bin/api with version injected |
make tidy | Format code (go fmt ./...) + tidy go.mod |
make test | Run all tests with verbose output |
make test-coverage | Generate coverage.html — open in browser |
make audit | go vet + staticcheck + race detector |
make compose-up | Start PostgreSQL + Redis via Docker |
make compose-down | Stop all Docker services |
make compose-logs | Tail service logs |
ALLOWED_CLIENTS Setup
Basic auth credentials are stored as a base64-encoded JSON array in the env var:
# Generate the value:
echo '[{"username":"dev","password":"secret"}]' | base64
# Paste result into .env:
ALLOWED_CLIENTS=W3sidXNlcm5hbWUiOiJkZXYiLCJwYXNzd29yZCI6InNlY3JldCJ9XQ==
# Test with curl:
curl -u dev:secret http://localhost:8080/coupon/api/v1/coupon/
Adding a Dependency
# Add a new library
go get github.com/some/library@v1.2.3
# Tidy (removes unused, updates go.sum)
go mod tidy
# or: make tidy
After adding: update lp-go-learning/COVERAGE.md if it's a significant new integration (see the site README).
Key Takeaways
cp .env.example .env— always do this first, never commit.envmake compose-upstarts dependencies;./migrate.sh upapplies DB migrationsmake tidybefore committing — formats code and keeps go.mod cleanmake auditruns the race detector — catches concurrency bugs locally