Go-HSR Template

Go HSR API Forge is a high-performance CLI tool designed to scaffold production-ready REST APIs in Go. It enforces a strict Clean Architecture pattern using the HSR (Handler, Service, Repository) methodology, enabling developers to build scalable microservices and APIs with zero boilerplate overhead.
π Why choose HSR?
- Instant Scaffolding - Generate a complete, industry-standard project structure in one command.
- Clean Architecture (HSR) - Logic is decoupled across layers (HTTP, Business, Data Access) for maximum testability.
- Developer First - Includes Docker support, standardized error handling, and robust middleware out of the box.
- Zero Configuration - Get a database-ready API with GORM and SQLite configured in seconds.
π¦ Getting Started
Prerequisites
- Go version: Go 1.22 or above.
Quick Start
Generate a new project directly from the terminal without cloning the repository:
1. Create a standard project:
go run [github.com/AP71/go-hsr@latest](https://github.com/AP71/go-hsr@latest) new ./my-new-api
2. Create a project with SQLite database support:
go run [github.com/AP71/go-hsr@latest](https://github.com/AP71/go-hsr@latest) new ./my-secured-api --auth
Next Steps
After generating your project:
cd my-new-api
go mod tidy
go run main.go
ποΈ Project Structure
my-new-api/
βββ config/ # Database and backup configurations
βββ docs/ # Swagger/OpenAPI documentation
βββ internal/
β βββ dto/ # Data Transfer Objects
β βββ handler/ # HTTP controllers
β βββ middleware/ # Auth and security layers
β βββ model/ # GORM domain entities
β βββ repository/ # Data access layer
β βββ router/ # Gin router initialization
β βββ service/ # Business logic
βββ pkg/apperror/ # Standardized error mapping
βββ utils/ # JWT, Hashing, and helper functions
βββ docker-compose.yml # Container orchestration
βββ Dockerfile # Multi-stage production build
π Documentation
Swagger API Reference
This project integrates swaggo/swag for automated API documentation.
- Install Swag CLI:
go install [github.com/swaggo/swag/cmd/swag@latest](https://github.com/swaggo/swag/cmd/swag@latest)
- Generate Swagger Docs:
swag init
- View API Docs:
Run the application and navigate to
http://localhost:8080/swagger/index.html to view the interactive API documentation.
π€ Contributing
We welcome contributions! Please feel free to open issues or submit pull requests.
π License
This project is licensed under the MIT License. See the LICENSE file for details.