A Go application that serves JSON content based on UUID lookups in a MySQL database.
- Retrieve JSON content by UUID via RESTful API
- Health check endpoint for monitoring
- Clean architecture with proper separation of concerns
- Production-ready with Docker support
- Domain Layer: Core business logic and rules
- Application Layer: Use cases and orchestration
- Infrastructure Layer: External concerns like databases
- Interface Layer: User interfaces like REST APIs
The application is divided into bounded contexts:
- Traffic Domain: Manages the storage and retrieval of traffic data
- Health Domain: Handles service health monitoring
- Common Domain: Shared domain concepts and utilities
traffic-controller/
├── cmd/
│ └── server/ # Application entry point
├── internal/
│ ├── common/ # Shared components
│ ├── traffic/ # Traffic domain
│ └── health/ # Health check domain
├── pkg/ # Public packages
├── api/ # API definitions
└── docker-compose.yml # Docker Compose configuration
GET /serve/{uuid}
- Returns JSON content for the specified UUIDGET /health
- Health check endpoint
- Go 1.21 or higher
- MySQL 8.0 or higher
- Docker (optional)
-
Clone the repository:
git clone https://github.com/githamo/stubhub-tc.git traffic-controller cd traffic-controller
-
Install dependencies:
go mod download
-
Create the database schema:
CREATE DATABASE IF NOT EXISTS trafficdb; USE trafficdb; CREATE TABLE endpoints ( id INT AUTO_INCREMENT PRIMARY KEY, uuid VARCHAR(36) UNIQUE NOT NULL, content VARCHAR(40) NOT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ); CREATE TABLE stub_contents ( id INT AUTO_INCREMENT PRIMARY KEY, filename VARCHAR(64) NOT NULL, content JSON NOT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP );
-
Configure environment variables:
cp .env.example .env # Edit .env with your database credentials & base64 encryption key
-
Run the application:
go run cmd/server/main.go
- Build and run with Docker Compose:
docker-compose up -d
Run tests:
go test ./...
curl http://localhost:8080/serve/550e8400-e29b-41d4-a716-446655440000
curl http://localhost:8080/health
This project is licensed under the MIT License - see the LICENSE file for details.