README
ΒΆ
GoPilot - Developer Tools API Platform
π§ GoPilot is a production-ready REST API platform that provides a comprehensive collection of modular developer tools. All endpoints are self-contained, require no external dependencies, and can be accessed directly from Swagger UI without writing code.
π― Vision
Provide a collection of modular REST APIs for various developer needs: URL shortening, encoding, data tools, file sharing, automation, and analytics β accessible directly from Swagger UI without writing code.
Features
- π URL Shortener - Create short links with custom aliases and expiration
- π Pastebin/Snippet Storage - Share code snippets with syntax highlighting
- π² QR Code Generator - Generate QR codes for URLs, text, and more
- π Hash & Encode - MD5, SHA, bcrypt, base64, hex encoding
- π Data Converter - Convert between bases, colors, time formats, JSON/YAML
- π UUID & Token Generator - Generate secure UUIDs and tokens
- π Mock Data Generator - Lorem ipsum, fake users, random numbers
- π¨ JSON/YAML Formatter - Format and convert structured data
- π Crypto Playground - AES, RSA, HMAC operations
- π RESTful API with comprehensive documentation
- π JWT Authentication for protected resources
- ποΈ PostgreSQL database with type-safe queries
- π Structured Logging with Zap
- π Prometheus Metrics for monitoring
- π OpenTelemetry tracing support
- π Interactive Swagger UI (OpenAPI 3)
- π§ Viper Configuration management
- π³ Docker support with multi-stage build
- β Automated Testing and linting
- π¦ CI/CD with GitHub Actions
Tech Stack
- Language: Go 1.22+
- Framework: Gin (REST router)
- Database: PostgreSQL 15+
- Query Builder: sqlc (type-safe SQL)
- Configuration: Viper (env + yaml)
- Logging: Zap (structured logs)
- Metrics: Prometheus
- Tracing: OpenTelemetry
- Documentation: Swagger/OpenAPI 3
- Authentication: JWT
- Migrations: golang-migrate
- Containerization: Docker
- CI/CD: GitHub Actions β GHCR
- License: MIT
π§© Core API Modules
1οΈβ£ URL Shortener
Create and manage shortened URLs with analytics.
Endpoints:
POST /v1/shorten- Create short link (original_url, optional alias, expire_in)GET /s/:code- Redirect to original URLGET /v1/shorten/:code- Get statistics
Features:
- Base62 ID generator
- Custom aliases
- Expiration support
- Click tracking (referrer, user agent, IP)
- Auto-cleanup of expired links
2οΈβ£ Pastebin / Snippet Storage
Store and share code snippets.
Endpoints:
POST /v1/paste- Create pasteGET /p/:id- View pasteDELETE /v1/paste/:id- Delete pasteGET /v1/paste/recent- List recent pastes
Features:
- TTL per paste (default 24h)
- Syntax highlighting support
- Public/private mode
- Compression option
3οΈβ£ QR Code Generator
Generate QR codes from text or URLs.
Endpoints:
POST /v1/qr- Generate QR codeGET /v1/qr/:id- Get QR code image
Features:
- PNG output
- Configurable size
- Persistent storage
4οΈβ£ Hash & Encode Utilities
Hash and encode text data.
Endpoints:
POST /v1/hash- Hash text (md5, sha1, sha256, sha512, bcrypt)POST /v1/encode- Encode/decode (base64, url, hex)POST /v1/generate/password- Generate secure passwords
Features:
- Multiple hash algorithms
- Configurable password generation
- Salt support for hashing
5οΈβ£ Base & Data Converter
Convert data between different formats.
Endpoints:
POST /v1/convert/base- Convert number bases (2-64)POST /v1/convert/color- RGB β HEX conversionPOST /v1/convert/time- Unix β ISO8601 β human readable
Features:
- Automatic type detection
- Validation and error handling
6οΈβ£ UUID & Token Generator
Generate UUIDs and random tokens.
Endpoints:
POST /v1/generate/uuid- Generate UUID v1/v4/v7POST /v1/generate/token- Generate random tokens
Features:
- Multiple UUID versions
- Custom prefix/suffix support
- Secure random generation
7οΈβ£ Lorem Ipsum & Mock Data
Generate fake data for testing.
Endpoints:
POST /v1/generate/lorem- Lorem ipsum textPOST /v1/generate/user- Fake user profilesPOST /v1/generate/number- Random numbers
Features:
- Configurable count
- Multiple data formats
- Realistic fake data
8οΈβ£ JSON / YAML Formatter
Format and convert structured data.
Endpoints:
POST /v1/format/json- Format/minify JSONPOST /v1/format/yaml- Convert JSON β YAML
Features:
- Validation checks
- Configurable indentation
- Syntax validation
9οΈβ£ Crypto Playground
Cryptographic operations for development.
Endpoints:
POST /v1/crypto/aes- AES encrypt/decryptPOST /v1/crypto/rsa/keygen- Generate RSA keypairPOST /v1/crypto/rsa- RSA encrypt/decryptPOST /v1/crypto/hmac- HMAC sign/verify
Features:
- Secure encryption
- Key generation
- Signature verification
- Ephemeral key storage (memory only)
Project Structure
gopilot/
βββ cmd/
β βββ server/ # Main application entry point
βββ internal/
β βββ config/ # Configuration management
β βββ domain/ # Domain models and DTOs
β βββ handler/ # HTTP handlers
β βββ middleware/ # Custom middlewares (JWT, etc.)
β βββ repository/ # Database repository layer
β β βββ db/ # Generated sqlc code
β βββ service/ # Business logic layer
βββ pkg/
β βββ logger/ # Logger utilities
β βββ metrics/ # Prometheus metrics
β βββ tracing/ # OpenTelemetry tracing
βββ db/
β βββ migrations/ # Database migration files
β βββ queries/ # SQL queries for sqlc
βββ docs/ # Swagger documentation
βββ Dockerfile # Multi-stage Docker build
βββ Makefile # Build automation
βββ docker-compose.yml # Local development setup
βββ .github/
βββ workflows/ # CI/CD pipelines
Getting Started
Prerequisites
- Go 1.21 or higher
- PostgreSQL 15+
- Docker (optional)
- Make (optional)
Installation
- Clone the repository:
git clone https://github.com/codewithwan/gopilot.git
cd gopilot
- Install dependencies:
go mod download
- Install development tools:
make install-tools
- Set up configuration:
cp config.yaml.example config.yaml
# Edit config.yaml with your settings
- Set up the database:
# Start PostgreSQL (using Docker)
docker run -d \
--name gopilot-postgres \
-e POSTGRES_USER=postgres \
-e POSTGRES_PASSWORD=postgres \
-e POSTGRES_DB=gopilot \
-p 5432:5432 \
postgres:15-alpine
# Run migrations
make migrate-up
- Run the application:
make run
The API will be available at http://localhost:8080
Using Docker Compose
For local development with all dependencies:
# Start all services
make dev
# Stop all services
make dev-down
API Documentation
Once the application is running, access the interactive Swagger UI at:
http://localhost:8080/swagger/index.html
or simply:
http://localhost:8080/docs
Quick Start API Examples
URL Shortener
# Create a short URL
curl -X POST http://localhost:8080/v1/shorten \
-H "Content-Type: application/json" \
-d '{"original_url":"https://example.com","expire_in":24}'
# Access the short URL (redirects)
curl http://localhost:8080/s/abc123
Pastebin
# Create a paste
curl -X POST http://localhost:8080/v1/paste \
-H "Content-Type: application/json" \
-d '{"content":"console.log(\"Hello\");","syntax":"javascript"}'
# View paste
curl http://localhost:8080/p/paste_id
QR Code
# Generate QR code
curl -X POST http://localhost:8080/v1/qr \
-H "Content-Type: application/json" \
-d '{"text":"https://example.com","size":256}'
# Download QR image
curl http://localhost:8080/v1/qr/qr_id -o qrcode.png
Hash & Encode
# Hash text
curl -X POST http://localhost:8080/v1/hash \
-H "Content-Type: application/json" \
-d '{"text":"password123","algorithm":"sha256"}'
# Base64 encode
curl -X POST http://localhost:8080/v1/encode \
-H "Content-Type: application/json" \
-d '{"text":"Hello World","operation":"base64-encode"}'
Generators
# Generate UUID
curl -X POST http://localhost:8080/v1/generate/uuid \
-H "Content-Type: application/json" \
-d '{"version":4,"count":5}'
# Generate password
curl -X POST http://localhost:8080/v1/generate/password \
-H "Content-Type: application/json" \
-d '{"length":16,"include_symbols":true}'
# Generate fake user
curl -X POST http://localhost:8080/v1/generate/user \
-H "Content-Type: application/json" \
-d '{"count":3}'
Converters
# Convert color
curl -X POST http://localhost:8080/v1/convert/color \
-H "Content-Type: application/json" \
-d '{"value":"#FF5733","to":"rgb"}'
# Format JSON
curl -X POST http://localhost:8080/v1/format/json \
-H "Content-Type: application/json" \
-d '{"json":"{\"key\":\"value\"}","minify":false,"indent":2}'
Crypto
# AES encrypt (use strong 32-character keys for AES-256)
curl -X POST http://localhost:8080/v1/crypto/aes \
-H "Content-Type: application/json" \
-d '{"operation":"encrypt","text":"secret","key":"strongkey32characterslongxxxx"}'
Legacy Endpoints (Todo App)
Authentication
POST /api/v1/auth/register- Register a new userPOST /api/v1/auth/login- Login and get JWT token
Todos (Protected)
GET /api/v1/todos- List all todosPOST /api/v1/todos- Create a new todoGET /api/v1/todos/:id- Get a specific todoPUT /api/v1/todos/:id- Update a todoDELETE /api/v1/todos/:id- Delete a todo
Health & Metrics
GET /health- Basic health checkGET /healthz- Kubernetes-style health checkGET /readyz- Readiness check (includes DB connectivity)GET /metrics- Prometheus metrics
Development
Building
# Build the binary
make build
# Build Docker image
make docker-build
Testing
# Run tests
make test
# Run tests with coverage
make test-coverage
Linting
make lint
Database Operations
# Generate sqlc code
make sqlc-generate
# Create a new migration
make migrate-create NAME=add_new_table
# Run migrations
make migrate-up
# Rollback migrations
make migrate-down
# Reset database
make db-reset
# Seed database with sample data (placeholder for future implementation)
make seed
Swagger Documentation
# Generate Swagger docs
make swagger-generate
# Or manually
swag init -g cmd/server/main.go -o docs
Code Generation
# Generate all code (sqlc + swagger)
make gen:openapi
Configuration
Configuration can be provided via:
- YAML config file (
config.yaml) - Environment variables (uppercase with underscores)
Example environment variables:
SERVER_PORT=8080
DATABASE_HOST=localhost
DATABASE_PORT=5432
DATABASE_USER=postgres
DATABASE_PASSWORD=postgres
DATABASE_DBNAME=gopilot
JWT_SECRET=your-secret-key
LOG_LEVEL=info
CI/CD
The project includes a comprehensive GitHub Actions workflow that:
- Runs linting with golangci-lint
- Executes tests with coverage
- Builds the application
- Builds and pushes Docker images to GitHub Container Registry (GHCR)
The workflow runs on:
- Every push to
mainbranch - Every pull request to
mainbranch
Docker images are pushed to GHCR only on pushes to the main branch.
Monitoring
Prometheus Metrics
The application exposes Prometheus metrics at /metrics. Key metrics include:
- HTTP request count and duration
- Database connection pool metrics
- Go runtime metrics
OpenTelemetry Tracing
To enable distributed tracing, configure the tracing endpoint in your config:
tracing:
enabled: true
serviceName: "gopilot"
endpoint: "otel-collector:4317"
Structured Logging
All logs are output in structured JSON format with fields:
- Level (debug, info, warn, error)
- Timestamp
- Message
- Context fields (request_id, user_id, etc.)
Example log output:
{
"level": "info",
"ts": 1234567890,
"msg": "Short URL created",
"code": "abc123",
"original_url": "https://example.com"
}
π₯οΈ Frontend (UI)
GoPilot uses Swagger UI as its primary frontend interface, allowing all APIs to be accessed directly without coding.
Features:
- β
Interactive API documentation at
/docs - β Request/response examples for all endpoints
- β Try-it-out functionality for testing
- β Built-in authentication support (JWT)
- β Auto-generated from OpenAPI spec
- β No frontend development needed
Architecture
GoPilot follows Clean Architecture principles:
βββββββββββββββββββββββββββββββββββββββ
β HTTP Handlers β (Gin Controllers)
βββββββββββββββββββββββββββββββββββββββ€
β Service Layer β (Business Logic)
βββββββββββββββββββββββββββββββββββββββ€
β Repository Layer β (Data Access)
βββββββββββββββββββββββββββββββββββββββ€
β Database (PostgreSQL + sqlc) β (Persistence)
βββββββββββββββββββββββββββββββββββββββ
Key Principles:
- Separation of concerns
- Dependency injection
- Interface-based design
- Testability
- Modularity
Production Deployment
Using Docker
Pull and run the latest image:
docker pull ghcr.io/codewithwan/gopilot:latest
docker run -p 8080:8080 \
-e DATABASE_HOST=your-db-host \
-e DATABASE_USER=your-db-user \
-e DATABASE_PASSWORD=your-db-password \
ghcr.io/codewithwan/gopilot:latest
Environment Variables
Required environment variables for production:
DATABASE_HOSTDATABASE_PORTDATABASE_USERDATABASE_PASSWORDDATABASE_DBNAMEJWT_SECRET(use a strong secret!)
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request