A robust "kickstarter" template for building backend applications using the Gin web framework in Go. This project provides a well-organized structure with essential features like MongoDB integration, JWT-based authentication, and middleware support. It aims to simplify the setup of a functional backend environment, allowing developers to focus on application-specific functionality.
While it provides a comprehensive starting point, it remains adaptable for further customization and expansion, allowing developers to incorporate additional architectural patterns or advanced features as needed. This makes it an effective foundation for creating scalable and maintainable web services in Go.
gin-backend-starter/
├── assets # Static files and resources
├── configs # Configuration files and setup, these would execute during the pre-start process of the server
├── helpers # Utility functions and common helpers
├── infra # Infrastructure-related code (database, logger, etc. that would be used throughout the app)
├── models # Data models and database schemas
├── routers # HTTP route definitions and handlers mapping
├── services # Business logic and service layer implementations
├── .env # Application config
├── .env.example
├── .gitignore
├── air.toml
├── go.mod
├── go.sum
├── LICENSE
├── main.go # Main entry point for the application
└── README.md
- Structured project layout for scalability
- Configuration management
- MongoDB integration
- JWT authentication
- User management
- Middleware support
- Logging
- Environment variable configuration
-
Clone the repository:
git clone https://github.com/imshawan/gin-backend-starter.git cd gin-backend-starter
-
Copy the example environment file and update the values:
cp .env.example .env
-
Install dependencies:
go mod tidy
-
Run the application:
go run main.go
Update the .env
file with your specific configurations before starting the app
POST /api/users/register
: Register a new userPOST /api/auth/sign-in
: User loginGET /api/users
: Get the currently logged-in user (protected route)GET /health
: Check the server status, if running
- Gin Web Framework for creating the REST APIs
- MongoDB Go Driver for communicating with MongoDB NoSql Database
- JWT Go for authentication purposes
- Viper for config management throughout the application
This project uses Air for live reloading during development. To use it:
-
Install Air:
go install github.com/air-verse/air@latest
-
Run the project using Air:
air
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b improvement/AmazingImprovements
) - Commit your changes (
git commit -m 'Added some amazing improvements'
) - Push to the branch (
git push origin improvement/AmazingImprovements
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.