Project ⏱ 6 min read

11 · Dev Environment

First-run checklist — from clone to running API

Prerequisites

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 runStart the API locally (go run main.go)
make buildCompile binary to bin/api with version injected
make tidyFormat code (go fmt ./...) + tidy go.mod
make testRun all tests with verbose output
make test-coverageGenerate coverage.html — open in browser
make auditgo vet + staticcheck + race detector
make compose-upStart PostgreSQL + Redis via Docker
make compose-downStop all Docker services
make compose-logsTail 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