go-plate
2 minute read
As I’ve developed my Glassdoor clone Compared and a few other smaller apps, I’ve tinkered around with Go a bit. I’ve tried quite a few different project structures and techniques, experimenting to find what works best for me.
After all that trial and error, I decided to put together this Go backend boilerplate project. It is supposed to serve as a distillation of all the lessons I’ve learned and a starting point that incorporates the patterns and practices I’ve found to be most effective. Something that allows me (and maybe you) to spin up a new project fast and be productive.
It also includes some examples of how to use it and how I like to structure my backends.
As of writing this, October 9, 2024, I consider it to be complete. There is of course much more a backend can encasulate, but for now that’s it.
As I continue learning and exploring, I’ll probably come back to it and add extra features.
Current features & overview:
- Routing with chi (Lightweight, 100% compatible with net/http)
- Environment variable management using godotenv
- CORS handling with cors
- Containerization with Docker
- API versioning via URL paths (
/api/v2/posts
) and custom headers (X-API-Version: v1
) - Request payload validation using validator
- SQL (PostgreSQL) integration with gorm ORM
- Database schema management with migrate for version-controlled and reproducible migrations
- Redis caching implementation with go-redis
- Secure password hashing and verification
- Authentication middleware with session management (Redis-backed)
- Rate Limiting (Implemented Token Bucket & Sliding Window, with in-memory storage for local rate limiting, and Redis for distributed systems across multiple server instances)
- CI/CD pipeline for GCP Cloud Run service
- CI/CD pipeline for AWS App Runner service
- Example endpoints to showcase functionality and use
- Documentation generation with Swagger