- OWASP Compliant Open API 3 Spec
- Middleware for
- Logging : Helps in debugging and monitoring
- Authentication : Placeholder for different authentication mechanisms
- Tracing by Request ID : Helps in debugging
- Panic Recovery : Helps in keeping the service up
- Common Security Headers : Keeps the service secure
- Query Params Validation : Helps in keeping the service secure
- Standard Error Handling
- All errors are handled and returned in a standard format
- Versioning
- Model Management
- Generally, the data model used internally is different from the data model exposed to the client. This helps in keeping the internal model separate from the exposed model.
- Configuration Management through Environment Variables
- A Dockerized environment to run the service
- A Makefile to do all common tasks
- A Git Action to build, run tests, generate code coverage
- Integrated GO Formatter and Linter
- Mechanism to load secrets from Sidecar
- Enables connecting to multiple databases
- Follows the best practices for connecting to MongoDB
- Good mocking practises for Unit test patterns
- Seed data for local development
- Standard filename conventions for better readability
- Multi-Stage Docker build for faster builds
- Versioning using git commit
- This is no way a complete solution for all your needs. This is just a boilerplate to start with.
- This is no way a starting point for a ecommerce application. What I provided is a simple CRUD API.
Pre-requisites: Docker, Docker Compose, Make
-
Start the service
make start
Other Options:
Choose a command to run in go-rest-api-example:
start Starts everything that is required to serve the APIs
run Run the API server alone (without supplementary services such as DB etc.,)
build Build the API server binary
version Display the current version of the API server
test Run tests
coverage Measures and generate code coverage report
tidy Tidy go modules
format Format go code
lint Run linter
lint-fix Run linter and fix the issues
docker-build Build the API server as a docker image
docker-run Run the API server as a docker container
docker-start Builds Docker image and runs it.
docker-stop Stops the docker container
docker-remove Removes the docker images and containers
docker-clean Cleans all docker resources
docker-clean-service-images Stops and Removes the service images
docker-clean-build-images Removes build images
owasp-report Generate OWASP report
go-work Generate the go work file
- Add more and clear documentation about the features this offers and how to replace tools
- Add DB Migration Support
- Add more profiles and obey all 12-Factor App rules
- Deploy to cloud
- Implement all OWASP security checks specified in the API Spec
- Improve error codes and messages
- Add missing references/inspirations
- Implement Update Operations mentioned in the API Spec
- Improve data model and add more fields
- Add git hooks for pre-commit and pre-push
- Please feel free to Open PRs
- Please create issues with any problem you noticed
- Please suggest any improvements
I ventured into creating my own open-source boilerplate repository for several reasons:
-
After years of crafting Full Stack applications using ReactJS and JVM-based languages, I found existing boilerplate's are either too much or too little. Hence, I decided to develop my own while adhering to the principles and guidelines of Go. While you may notice similarities with popular Go boilerplate templates, I've tailored this repository to align more closely with my preferences and experiences. (Apologies if I inadvertently missed crediting any existing templates.)
-
I desired the freedom to handpick the tools for essential functionalities like Routing, Logging, and Configuration Management, ensuring they align perfectly with my preferences and requirements.
-
Creating my own version allows me complete control to adapt and update the boilerplate according to the specific needs and demands of my professional work. This flexibility enables me to continually refine and optimize the repository based on evolving project requirements.