A comprehensive example of a production-ready RESTful API built with Gin framework, featuring modern Go practices, security best practices, JWT authentication, file upload, WebSocket support, and complete CI/CD integration.
- π Modern Go 1.24 with latest stable dependencies
- π JWT Authentication with role-based access control
- π¦ CRUD Operations for users and products
- ποΈ GORM Integration with SQLite (easily switchable to MySQL/PostgreSQL)
- π File Upload Management with security validation
- π WebSocket Support for real-time communication
- β Request Validation using Gin's binding
- π Security Hardened - gosec verified, zero vulnerabilities
- π§ͺ Unit Tests with testify
- π Structured Logging with zerolog
- βοΈ Configuration Management with Viper
- π¦ Rate Limiting middleware
- π Pagination & Search for list endpoints
- β GitHub Actions - automated testing and security scanning
- π CircleCI ready configuration
- π³ Docker & Docker Compose support
- π CodeQL Security Analysis
- π‘οΈ Dependabot integration
Go Build and Test CodeQL Security Scanning
- Go 1.24 or higher
- Make (optional, for convenience commands)
# Clone the repository git clone https://github.com/wmh/my-gin-example.git cd my-gin-example # Install dependencies go mod download # Run the application go run main.go
The server will start on http://localhost:8089 by default.
Create or edit config/app.toml:
app_port = 8089 [database] driver = "sqlite" dsn = "./data/my_gin_example.db" [jwt] secret = "your-secret-key-here" expires_hours = 24 [logs] common_log = "./data/logs/common.log" stdout_only = false [upload] max_size = 10485760 # 10MB allowed_types = ["image/jpeg", "image/png", "image/gif", "application/pdf"]
POST /api/v1/auth/register- Register new userPOST /api/v1/auth/login- Login and get JWT token
GET /api/v1/users- List users (with pagination)GET /api/v1/users/:id- Get user detailsPUT /api/v1/users/:id- Update userDELETE /api/v1/users/:id- Delete user
GET /api/v1/products- List products (with pagination & search)POST /api/v1/products- Create productGET /api/v1/products/:id- Get product detailsPUT /api/v1/products/:id- Update productDELETE /api/v1/products/:id- Delete product
POST /api/v1/files/upload- Upload single filePOST /api/v1/files/batch-upload- Upload multiple filesGET /api/v1/files- List uploaded filesGET /api/v1/files/:id- Get file detailsGET /api/v1/files/:id/download- Download fileDELETE /api/v1/files/:id- Delete file
GET /ws- WebSocket connection for real-time updates
GET /ok- Simple health check
# Run all tests go test ./... # Run tests with coverage go test -cover ./... # Run specific package tests go test ./app/services/...
This project follows security best practices:
- β Zero vulnerabilities - verified by govulncheck
- β gosec compliant - all security warnings resolved
- β Path traversal protection - file operations validated
- β Secure file permissions - 0600 for files, 0750 for directories
- β HTTP timeout configuration - protection against slowloris attacks
- β Regular dependency updates - via Dependabot
Run security checks locally:
# Check for vulnerabilities govulncheck ./... # Run security scanner gosec ./...
# Build Docker image docker build -t my-gin-example . # Run with Docker Compose docker-compose up -d
# Run the application make run # Run tests make test # Build binary make build # Run with hot reload (using air) make dev # Clean build artifacts make clean
my-gin-example/
βββ app/
β βββ controllers/ # Request handlers
β βββ core/ # Core functionality (config, db, logger)
β βββ models/ # Database models
β βββ routes/ # Route definitions
β βββ services/ # Business logic
βββ config/ # Configuration files
βββ data/ # Database and uploads
βββ scripts/ # Utility scripts
βββ tests/ # Integration tests
βββ main.go # Application entry point
- FEATURES.md - Detailed feature documentation
- CHANGELOG.md - Version history and changes
- QUICKSTART.md - Quick start guide
Contributions are welcome! Please feel free to submit a Pull Request.
- 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
This project is open source and available under the MIT License.
Built with:
For questions or feedback, please open an issue on GitHub.
Version: 2.0.0
Go Version: 1.24+
Last Updated: December 2025