Personal multi-sport activity tracking API built with Go.
Week 1 Complete - Basic API structure with mock endpoints
- Health check endpoint
- Mock activity listing
- Mock activity creation
- JSON response handling
- Proper project structure
- Go 1.21+
- gorilla/mux for routing
- PostgreSQL (coming in Week 2)
- Go 1.21 or higher
- Git
- Clone the repository:
git clone https://github.com/yourusername/activelog.git
cd activelog- Install dependencies:
go mod download- Run the server:
go run cmd/api/main.goServer will start on http://localhost:8080
GET /healthResponse:
{
"status": "healthy",
"service": "activelog-api"
}Add filtering examples:
## API Endpoints
### List Activities
```bash
GET /api/v1/activities?type=running&limit=10&offset=0&start_date=2024-12-01T00:00:00ZQuery Parameters:
type- Filter by activity typelimit- Number of results (max 100, default 10)offset- Pagination offsetstart_date- Filter activities after this date (RFC3339 format)end_date- Filter activities before this date (RFC3339 format)
Response:
{
"activities": [...],
"count": 10,
"total": 45,
"limit": 10,
"offset": 0
}POST /api/v1/activities
Content-Type: application/json
{
"activity_type": "running",
"title": "Morning Run",
"duration_minutes": 30,
"distance_km": 5.2,
"activity_date": "2024-12-24T07:00:00Z"
}Validation Rules:
activity_type: required, 2-50 characterstitle: optional, max 255 charactersduration_minutes: optional, 1-1440 (max 24 hours)distance_km: optional, must be positiveactivity_date: required, RFC3339 format
Error Response:
{
"error": "Validation failed",
"fields": {
"activity_type": "activity_type is required",
"activity_date": "activity_date is required"
}
}ActiveLog supports powerful TypeORM-style dynamic filtering with natural column names for relationships.
Filter by activity type:
GET /api/v1/activities?filter[activity_type]=runningFilter by tag (auto-JOIN):
GET /api/v1/activities?filter[tags.name]=cardioDate range filtering:
GET /api/v1/activities?filter[activity_date][gte]=2024-01-01&filter[activity_date][lte]=2024-12-31Search and sort:
GET /api/v1/activities?search[title]=morning&order[distance_km]=DESC&page=1&limit=20Complex query with relationships:
GET /api/v1/activities?filter[tags.name]=cardio&filter[user.username]=john&search[title]=run&order[activity_date]=DESC- ✅ Natural column names - Use
tags.nameinstead of aliases - ✅ Auto-JOIN detection - Relationships detected from dot notation
- ✅ Operator filtering - Support for
eq,ne,gt,gte,lt,lte - ✅ Secure - Column whitelisting prevents unauthorized access
- ✅ Performant - Parameterized queries with automatic indexing
| Operator | Description | Example |
|---|---|---|
eq |
Equal (default) | filter[distance_km][eq]=10 |
ne |
Not equal | filter[activity_type][ne]=running |
gt |
Greater than | filter[distance_km][gt]=5.0 |
gte |
Greater than or equal | filter[activity_date][gte]=2024-01-01 |
lt |
Less than | filter[duration_minutes][lt]=60 |
lte |
Less than or equal | filter[activity_date][lte]=2024-12-31 |
For complete filtering and querying documentation, see:
- Query Guide - Complete guide to filtering, ordering, and relationships
- Architecture Documentation - System architecture overview
activelog/
├── cmd/
│ └── api/ # Application entry point
│ └── main.go
├── internal/
│ ├── handlers/ # HTTP request handlers
│ └── models/ # Data models (coming soon)
├── pkg/
│ └── response/ # Reusable response utilities
├── go.mod
├── go.sum
└── README.md
go test ./...go fmt ./...- Project structure
- Basic HTTP server
- Routing with gorilla/mux
- JSON response helpers
- Basic tests
Add database setup instructions:
- Create database and user:
psql postgres
CREATE DATABASE activelog_dev;
CREATE USER activelog_user WITH PASSWORD 'your_secure_password';
GRANT ALL PRIVILEGES ON DATABASE activelog_dev TO activelog_user;
\q- Run migrations:
migrate -path migrations -database "postgres://activelog_user:your_secure_password@localhost/activelog_dev?sslmode=disable" up- Create a test user:
psql activelog_dev -U activelog_user
INSERT INTO users (email, username) VALUES ('test@example.com', 'testuser');
\qThis is a learning project following a 12-month Go mastery plan.
- Go project structure is more opinionated than JavaScript
- Handlers implement ServeHTTP interface
- Testing is built into Go (no Jest/Mocha needed)
- Error handling is explicit (no try-catch)