Level 5: Capstone Unified Service (API Integration & Gin)¶
Welcome to the final level! Here, you will integrate everything you have built in Levels 1 through 4 into a single, cohesive backend gateway using Gin.
This project simulates a professional, production-grade microservice gateway that handles HTTP requests, concurrent file parsing, shortlink redirection, database storage, and live WebSockets.
Architecture & Integration Diagram¶
graph TD
Client["Web & API Clients"] <-->|"HTTP & WebSockets"| Gin["Gin Router / API Gateway"]
subgraph CORE_MODULES ["Core Modules"]
Gin <-->|CRUD| Level1["Level 1: Task Manager"]
Gin --->|"Multipart Uploads"| Level2["Level 2: Log Analyzer"]
Gin <-->|"Shortening & Hits"| Level3["Level 3: URL Shortener"]
Gin <-->|"Event Dispatch"| Level4["Level 4: Real-time Websocket Hub"]
end
Level4 <-->|"Pub/Sub Sync"| Redis["Redis Broker"]
API Endpoints to Support¶
Your unified API server must handle:
1. Task Tracker CRUD (Level 1)¶
GET /tasks: Return all tasks in JSON.POST /tasks: Expects{"description": "Task Text"}. Adds task and publishes a WebSocket event notification:{"event": "task_created", "task": ...}.PUT /tasks/:id/complete: Marks task complete. Publishes WebSocket notification:{"event": "task_completed", "id": 1}.
2. Concurrent Log Analyzer (Level 2)¶
POST /logs/analyze: Expects multipart form file uploads. Parses all uploaded logs concurrently using your Level 2 concurrent engine, aggregates findings, and returns the unifiedLogResultsummary JSON.
3. URL Shortener (Level 3)¶
POST /shorten: Expects{"url": "https://..."}. Saves short link and publishes WebSocket notification:{"event": "url_shortened", "code": "abcde"}.GET /:short_code: Increments hit counter, redirects browser, and publishes WebSocket notification:{"event": "url_hit", "code": "abcde", "hits": 5}.
4. Live Event Feed (Level 4)¶
GET /ws: Upgrades the connection to WebSockets. Subscribes the client to the Level 4 Event Hub so they receive all the live event messages dispatched by the other endpoints.
Getting Started¶
- Ensure the
go.modis set up with dependencies. Run this to fetch Gin and gorilla/websocket: - See main.go for the integration router stubs.
- See main_test.go for the endpoint test suite.
- Run tests: