- OWASP Compliant Open API 3 Specification: Refer to OpenApi-v1.yaml for details.
- Middleware for:
- Logging: Facilitates debugging and monitoring processes.
- Authentication: Provides a placeholder for diverse authentication mechanisms.
- Tracing by Request ID: Assists in debugging procedures.
- Panic Recovery: Ensures service continuity by managing unexpected errors.
- Common Security Headers: Safeguards the service against potential vulnerabilities.
- Query Parameters Validation: Enhances service security by validating query parameters.
- Standardized Error Handling: All errors are managed and returned in a uniform format.
- Versioning
- Model Management:
- Internally used data models differ from those exposed to clients, ensuring separation and security.
- Configuration Management: via Environment Variables
- Dockerized Environment: Facilitates service deployment.
- Makefile: Automates common tasks for developers.
- Git Action: Automates build processes, runs tests, and generates code coverage.
- Integrated Go Formatter and Linter: Promotes code quality and consistency.
- Secrets Loading Mechanism from Sidecar
- Support for Multiple Databases: Enables connections to various database systems.
- Best Practices for MongoDB Connection
- Effective Mocking Practices for Unit Test Patterns
- Seed Data: for Local Development
- Standardized Filename Conventions: Enhances code readability.
- Multi-Stage Docker Build: Accelerates build processes.
- Versioning Utilizing Git Commit History
go-rest-api-example/
├── main.go
├── internal/
│ ├── db
│ ├── errors
│ ├── handlers
│ ├── logger
│ ├── middleware
│ ├── models
│ ├── server
│ ├── util
│ └── mockData
├── localDevelopment/
├── Makefile
├── Dockerfile
├── OpenApi-vi.yaml
├── docker-compose.yaml
└── OpenApi-v1.postman_collection.json
- Docker
- Docker Compose
- Make
- golangci-lint
start Start all necessary services and API server
run Run the API server
setup Start only dependencies
test Run tests with coverage
lint Run the linter
lint-fix Run the linter and fix issues
clean Clean all Docker resources
coverage Generate and display the code coverage report
go-work Generate Go work file
owasp-report Generate OWASP report
tidy Tidy Go modules
build Build the API server binary
ci-coverage Check if test coverage meets the threshold
format Format Go code
version Display the current version of the API server
docker-build Build the Docker image
docker-build-debug Build the Docker image without cache
docker-clean Clean all Docker resources
docker-clean-build-images Remove build images
docker-remove Remove Docker images and containers
docker-run Run the Docker container
docker-start Build and run the Docker container
docker-stop Stop the Docker container
- Add more and clear documentation about the features this offers and how to replace tools
- Add DB Migration Support
- Add more environmental profiles and obey all 12-Factor App rules
- Implement all OWASP security checks specified in the API Spec
- Improve error codes and messages
- Add git hooks for pre-commit and pre-push
- Improve data model and add more fields
- Deploy to cloud
- Implement Update Operations mentioned in the API Spec
- Please feel free to Open PRs
- Please create issues with any problem you noticed
- Please suggest any improvements
I embarked on the endeavor of crafting my own open-source boilerplate repository for several reasons:
After years of developing Full Stack applications utilizing ReactJS and JVM-based languages, I observed that existing boilerplate's tended to be either excessive or insufficient for my needs. Consequently, I resolved to construct my own, while adhering rigorously to the principles and guidelines of Go. While similarities with popular Go boilerplate templates may be evident, I have customized this repository to better align with my preferences and accumulated experiences. (My apologies if I inadvertently overlooked crediting any existing templates.)
I yearned for the autonomy to meticulously select the tools for fundamental functionalities such as Routing, Logging, and Configuration Management, ensuring seamless alignment with my personal preferences and specific requirements.
- This isn't a complete solution for all your needs. It's more like a basic template to kickstart your project.
- This isn't the best place to begin if you want to make an online store. What I've provided is just a simple tool for managing data through an API.