How yonger0718/go-template works
Project Type and Purpose
• This is a Go “template” or boilerplate for a RESTful API server.
• It provides HTTP endpoints (via Swagger docs), user authentication (JWT), data persistence (database), and is wired together with Google Wire for dependency injection.
• It’s intended as a starting point for a typical layered, full-stack back-end service.
File Structure
• cmd/go-template – the entrypoint containing main.go (app bootstrap) and Wire setup.
• internal/server – HTTP server instantiation.
• internal/api/handlers – route definitions, request/response handling, error handling.
• internal/services – business logic (e.g., user service).
• internal/repository – data access layer (e.g., user repository).
• internal/utils – cross-cutting helpers: database connection, JWT generation/validation, logging.
• internal/middleware – HTTP middleware, e.g., auth.
• internal/configs – configuration loader (YAML).
• assets/swagger – OpenAPI specs.
• deploy/docker-compose.yml – service composition (e.g., database container).
• migration – DB migration runner.
Main Components & Layers
1. Presentation Layer
– HTTP Server (listening on port)
– Middleware (auth, logging)
– API Handlers / Routes (user, exception, response)
2. Application / Business Layer
– Services (user service interface & implementation)
3. Data Access Layer
– Repositories (user repository)
4. Infrastructure & Utilities
– Database connector (GORM or raw SQL)
– JWT utility
– Logger
– Configuration loader
– Dependency Injection (Wire)
5. External Systems
– PostgreSQL (or other RDBMS)
– Redis / external caches, if any (not present here)
Architectural Patterns & Design Principles
• Layered Architecture – strict separation of concerns.
• Dependency Injection – using Wire to assemble handlers, services, repos.
• Repository Pattern – abstract persistence behind interfaces.
• Middleware Pipeline – for cross-cutting concerns (authentication, logging, error handling).
• Configuration-first – load configs once at startup and inject.
• A note on the side showing your deployment stack (Docker-Compose).
• Optionally: indicate test boundaries (e.g., internal/utils/logger_test.go).