A modern, feature-rich RESTful API boilerplate built with Go and Echo framework. This project provides a solid foundation for building scalable and maintainable web services with best practices baked in.
- Echo Framework: High performance, extensible, minimalist Go web framework
- GORM: The fantastic ORM library for Golang
- Casbin: Powerful and efficient open-source access control library
- RabbitMQ: Message broker for asynchronous processing
- WebSockets: Real-time communication between server and clients
- Swagger: Automated API documentation
- Viper: Complete configuration solution
- Zerolog: Zero allocation JSON logger
- Validator: Request validation
- Rate Limiting: Built-in protection against DoS attacks
- Graceful Shutdown: Proper handling of server shutdown
- Go 1.24+ (installation instructions)
- PostgreSQL (installation instructions)
- RabbitMQ (installation instructions)
- Docker and Docker Compose (optional, for containerized development)
git clone <repository-url>
cd go-rest-boilerplate-echo
make dep
# or manually:'
go mod download
# Copy the example config file
cp config.yaml.example config.yaml
# Edit the config file with your database and RabbitMQ credentials
# using your favorite text editor
vim config.yaml
The project includes a Docker Compose configuration for local development:
make start-services
This will start PostgreSQL and RabbitMQ containers.
go run ./database/migrate/migrate.go
make serve
# or manually:
go run main.go
The API will be available at http://localhost:8080
Once the server is running, access the Swagger documentation at:
http://localhost:8080/swagger/index.html
βββ config/ # Configuration files and functionality
βββ database/ # Database connection and models
βββ βββ migrate/ # Database migration scripts
βββ βββ models/ # Database models (GORM)
βββ docs/ # API documentation (Swagger)
βββ handlers/ # HTTP request handlers
βββ policy/ # Authorization policies (Casbin)
βββ rabbitmq/ # Message queue clients and task management
βββ websocket/ # WebSocket server implementation
βββ main.go # Application entry point
βββ config.yaml.example # Example configuration file
The boilerplate includes a fully-functional tenant management API:
Method | Endpoint | Description |
---|---|---|
GET | /tenants | Get a list of all tenants |
GET | /tenants/:id | Get a specific tenant by ID |
POST | /tenants | Create a new tenant |
PUT | /tenants | Update an existing tenant |
DELETE | /tenants/:id | Delete a tenant |
GET | /swagger/* | Swagger API documentation |
The boilerplate uses Casbin for access control. Policies are defined in the policy/policy.go
file and can be customized according to your requirements.
Tasks are processed asynchronously using RabbitMQ. The system includes:
- Push and listen queues
- Task status tracking
- Real-time updates via WebSockets
Run tests using:
make test
# or manually:
go test ./...
For test coverage:
make coverage
Build the Docker image:
docker build -t go-rest-boilerplate-echo .
Run the container:
docker run -p 8080:8080 go-rest-boilerplate-echo
This project follows the standard Go code style conventions:
# Format code
go fmt ./...
# Check for code issues
go vet ./...
- Create a new model file in the
database/models/
directory - Add the model to the migration process in
database/migrate/migrate.go
- Create a handler in the
handlers/
directory - Register routes in
main.go
- Add authorization policies in
policy/policy.go
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.