π»π³ TiαΊΏng Viα»t | π¬π§ English
A template for quickly scaffolding Go microservices following Clean Architecture + golang-standards/project-layout.
.\init-service.ps1 -ServiceName point-servicechmod +x init-service.sh
./init-service.sh point-service./init-service.sh reward-service ./my-services/reward-servicego-service-template/
βββ cmd/api/main.go # Entry point
βββ internal/
β βββ app/app.go # DI container
β βββ config/config.go # Configuration
β βββ entity/example.go # Domain entities
β βββ usecase/
β β βββ interfaces.go # Repository interfaces
β β βββ example.go # Business logic
β βββ controller/http/
β β βββ server.go # HTTP server
β β βββ middleware.go # Middlewares
β β βββ v1/ # API v1 handlers
β βββ infrastructure/
β βββ repository/postgres/ # PostgreSQL repos
β βββ cache/redis/ # Redis cache
β βββ messaging/kafka/ # Kafka producer
βββ migrations/ # SQL migrations
βββ Dockerfile
βββ Makefile
βββ .env.example
βββ README.md
-
Update entity -
internal/entity/example.go- Rename
Exampleto your domain entity - Add required fields
- Rename
-
Update usecase -
internal/usecase/- Rename
ExampleUseCase - Implement business logic
- Rename
-
Update repository -
internal/infrastructure/repository/postgres/- Rename
ExampleRepository - Implement data access
- Rename
-
Update handlers -
internal/controller/http/v1/- Rename handlers
- Add API endpoints
-
Update migrations -
migrations/- Rename table
examples - Add schema for your domain
- Rename table
./init-service.sh point-service
# Then:
# - Rename Example -> PointAccount, PointTransaction
# - Implement EarnPoints, RedeemPoints use cases
# - Add APIs: POST /points/earn, POST /points/redeemβββββββββββββββββββββββββββββββββββββββββββ
β Frameworks & Drivers β β infrastructure/
β (DB, Cache, Messaging) β
βββββββββββββββββββββββββββββββββββββββββββ€
β Interface Adapters β β controller/
β (HTTP, gRPC handlers) β
βββββββββββββββββββββββββββββββββββββββββββ€
β Application Business Rules β β usecase/
β (Use Cases) β
βββββββββββββββββββββββββββββββββββββββββββ€
β Enterprise Business Rules β β entity/
β (Entities) β
βββββββββββββββββββββββββββββββββββββββββββ
entity/β No dependenciesusecase/β Depends only onentity/, defines interfacescontroller/β Depends onusecase/infrastructure/β Implements interfaces fromusecase/
Template Δα» tαΊ‘o nhanh microservice Go theo Clean Architecture + golang-standards/project-layout.
.\init-service.ps1 -ServiceName point-servicechmod +x init-service.sh
./init-service.sh point-service./init-service.sh reward-service ./my-services/reward-servicego-service-template/
βββ cmd/api/main.go # Entry point
βββ internal/
β βββ app/app.go # DI container
β βββ config/config.go # Configuration
β βββ entity/example.go # Domain entities
β βββ usecase/
β β βββ interfaces.go # Repository interfaces
β β βββ example.go # Business logic
β βββ controller/http/
β β βββ server.go # HTTP server
β β βββ middleware.go # Middlewares
β β βββ v1/ # API v1 handlers
β βββ infrastructure/
β βββ repository/postgres/ # PostgreSQL repos
β βββ cache/redis/ # Redis cache
β βββ messaging/kafka/ # Kafka producer
βββ migrations/ # SQL migrations
βββ Dockerfile
βββ Makefile
βββ .env.example
βββ README.md
-
CαΊp nhαΊt entity -
internal/entity/example.go- Δα»i tΓͺn
ExamplethΓ nh domain entity cα»§a bαΊ‘n - ThΓͺm cΓ‘c fields cαΊ§n thiαΊΏt
- Δα»i tΓͺn
-
CαΊp nhαΊt usecase -
internal/usecase/- Δα»i tΓͺn
ExampleUseCase - Implement business logic
- Δα»i tΓͺn
-
CαΊp nhαΊt repository -
internal/infrastructure/repository/postgres/- Δα»i tΓͺn
ExampleRepository - Implement data access
- Δα»i tΓͺn
-
CαΊp nhαΊt handlers -
internal/controller/http/v1/- Δα»i tΓͺn handlers
- ThΓͺm API endpoints
-
CαΊp nhαΊt migrations -
migrations/- Δα»i tΓͺn table
examples - ThΓͺm schema cho domain
- Δα»i tΓͺn table
./init-service.sh point-service
# Sau ΔΓ³:
# - Δα»i Example -> PointAccount, PointTransaction
# - Implement EarnPoints, RedeemPoints use cases
# - ThΓͺm API: POST /points/earn, POST /points/redeemβββββββββββββββββββββββββββββββββββββββββββ
β Frameworks & Drivers β β infrastructure/
β (DB, Cache, Messaging) β
βββββββββββββββββββββββββββββββββββββββββββ€
β Interface Adapters β β controller/
β (HTTP, gRPC handlers) β
βββββββββββββββββββββββββββββββββββββββββββ€
β Application Business Rules β β usecase/
β (Use Cases) β
βββββββββββββββββββββββββββββββββββββββββββ€
β Enterprise Business Rules β β entity/
β (Entities) β
βββββββββββββββββββββββββββββββββββββββββββ
entity/β KhΓ΄ng phα»₯ thuα»c gΓ¬usecase/β Chα» phα»₯ thuα»centity/, Δα»nh nghΔ©a interfacescontroller/β Phα»₯ thuα»cusecase/infrastructure/β Implement interfaces tα»«usecase/