Skip to content

Commit af52fdb

Browse files
committed
feat: update README to reflect addition of NATS RPC and enhance domain descriptions
1 parent 55090c8 commit af52fdb

File tree

3 files changed

+177
-27
lines changed

3 files changed

+177
-27
lines changed

README.md

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Using the principles of Robert Martin (aka Uncle Bob).
3636
[Go-clean-template](https://evrone.com/go-clean-template?utm_source=github&utm_campaign=go-clean-template) is created &
3737
supported by [Evrone](https://evrone.com/?utm_source=github&utm_campaign=go-clean-template).
3838

39-
This template implements three types of servers:
39+
This template implements four types of servers:
4040

4141
- AMQP RPC (based on RabbitMQ as [transport](https://github.com/rabbitmq/amqp091-go)
4242
and [Request-Reply pattern](https://www.enterpriseintegrationpatterns.com/patterns/messaging/RequestReply.html))
@@ -55,11 +55,56 @@ All domains are available across all four transports (REST, gRPC, AMQP RPC, NATS
5555

5656
## Content
5757

58+
- [Domains](#domains)
5859
- [Quick start](#quick-start)
5960
- [Project structure](#project-structure)
6061
- [Dependency Injection](#dependency-injection)
6162
- [Clean Architecture](#clean-architecture)
6263

64+
## Domains
65+
66+
The template includes three fully implemented domains, each available across all four transports (REST, gRPC, AMQP RPC, NATS RPC).
67+
68+
### User Authentication
69+
70+
Registration, login, and JWT-based authorization.
71+
72+
| Operation | REST | gRPC |
73+
|-------------|--------------------------|--------------------------|
74+
| Register | `POST /v1/auth/register` | `AuthService/Register` |
75+
| Login | `POST /v1/auth/login` | `AuthService/Login` |
76+
| Get profile | `GET /v1/user/profile` | `AuthService/GetProfile` |
77+
78+
- Passwords hashed with bcrypt
79+
- JWT tokens with configurable expiry
80+
- Auth middleware on all transports
81+
82+
### Task Management
83+
84+
CRUD operations with a status state machine.
85+
86+
| Operation | REST | gRPC |
87+
|------------|------------------------------|------------------------------|
88+
| Create | `POST /v1/tasks` | `TaskService/CreateTask` |
89+
| List | `GET /v1/tasks` | `TaskService/ListTasks` |
90+
| Get | `GET /v1/tasks/:id` | `TaskService/GetTask` |
91+
| Update | `PUT /v1/tasks/:id` | `TaskService/UpdateTask` |
92+
| Transition | `PATCH /v1/tasks/:id/status` | `TaskService/TransitionTask` |
93+
| Delete | `DELETE /v1/tasks/:id` | `TaskService/DeleteTask` |
94+
95+
- Status transitions: `todo``in_progress``done` (and `in_progress``todo`)
96+
- Pagination with `limit`/`offset` and optional status filter
97+
- Tasks scoped to the authenticated user
98+
99+
### Translation
100+
101+
Text translation via external API with history tracking.
102+
103+
| Operation | REST | gRPC |
104+
|-----------|-------------------------------------|-----------------------------------------|
105+
| Translate | `POST /v1/translation/do-translate` | `TranslationHistoryService/DoTranslate` |
106+
| History | `GET /v1/translation/history` | `TranslationHistoryService/ShowHistory` |
107+
63108
## Quick start
64109

65110
### Local development
@@ -171,9 +216,10 @@ go run -tags migrate ./cmd/app
171216

172217
### `internal/controller`
173218

174-
Server handler layer (MVC controllers). The template shows 3 servers:
219+
Server handler layer (MVC controllers). The template shows 4 servers:
175220

176221
- AMQP RPC (based on RabbitMQ as transport)
222+
- NATS RPC (based on NATS as transport)
177223
- gRPC ([gRPC](https://grpc.io/) framework based on protobuf)
178224
- REST API ([Fiber](https://github.com/gofiber/fiber) framework)
179225

@@ -193,7 +239,7 @@ And in the file `internal/controller/amqp_rpc/router.go` add the line:
193239
routes := make(map[string]server.CallHandler)
194240

195241
{
196-
v1.NewTranslationRoutes(routes, t, l)
242+
v1.NewRoutes(routes, t, u, tk, j, l)
197243
}
198244

199245
{
@@ -210,10 +256,14 @@ And in the file `internal/controller/grpc/router.go` add the line:
210256

211257
```go
212258
{
259+
v1.NewAuthRoutes(app, u, l)
260+
v1.NewTaskRoutes(app, tk, l)
213261
v1.NewTranslationRoutes(app, t, l)
214262
}
215263

216264
{
265+
v2.NewAuthRoutes(app, u, l)
266+
v2.NewTaskRoutes(app, tk, l)
217267
v2.NewTranslationRoutes(app, t, l)
218268
}
219269

@@ -230,7 +280,7 @@ And in the file `internal/controller/nats_rpc/router.go` add the line:
230280
routes := make(map[string]server.CallHandler)
231281

232282
{
233-
v1.NewTranslationRoutes(routes, t, l)
283+
v1.NewRoutes(routes, t, u, tk, j, l)
234284
}
235285

236286
{
@@ -247,11 +297,11 @@ And in the file `internal/controller/restapi/router.go` add the line:
247297
```go
248298
apiV1Group := app.Group("/v1")
249299
{
250-
v1.NewTranslationRoutes(apiV1Group, t, l)
300+
v1.NewRoutes(apiV1Group, t, u, tk, jwtManager, l)
251301
}
252302
apiV2Group := app.Group("/v2")
253303
{
254-
v2.NewTranslationRoutes(apiV2Group, t, l)
304+
v2.NewRoutes(apiV2Group, t, u, tk, jwtManager, l)
255305
}
256306
```
257307

@@ -328,7 +378,7 @@ func (uc *UseCase) Do() {
328378
}
329379
```
330380

331-
It will also allow us to do auto-generation of mocks (for example with [mockery](https://github.com/vektra/mockery)) and
381+
It will also allow us to do auto-generation of mocks (for example with [go.uber.org/mock](https://go.uber.org/mock)) and
332382
easily write unit tests.
333383

334384
> We are not tied to specific implementations in order to always be able to change one component to another.
@@ -414,9 +464,9 @@ Or more complex business logic:
414464
- **Use Cases** is business logic located in `internal/usecase`.
415465

416466
The layer with which business logic directly interacts is usually called the _infrastructure_ layer.
417-
These can be repositories `internal/usecase/repo`, external webapi `internal/usecase/webapi`, any pkg, and other
467+
These can be repositories `internal/repo/persistent`, external webapi `internal/repo/webapi`, any pkg, and other
418468
microservices.
419-
In the template, the _infrastructure_ packages are located inside `internal/usecase`.
469+
In the template, the _infrastructure_ packages are located inside `internal/repo`.
420470

421471
You can choose how to call the entry points as you wish. The options are:
422472

README_CN.md

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ golang服务的整洁架构模板
3333
[Go 整洁模板](https://evrone.com/go-clean-template?utm_source=github&utm_campaign=go-clean-template)
3434
[Evrone](https://evrone.com/?utm_source=github&utm_campaign=go-clean-template) 创建和提供支持.
3535

36-
此模板实现了三种类型的服务器
36+
此模板实现了四种类型的服务器
3737

3838
- AMQP RPC(基于 RabbitMQ 作为传输)
3939
- NATS RPC(基于 NATS 作为传输)
@@ -50,11 +50,56 @@ golang服务的整洁架构模板
5050

5151
## 内容
5252

53+
- [领域](#领域)
5354
- [快速开始](#快速开始)
5455
- [工程架构](#工程架构)
5556
- [依赖注入](#依赖注入)
5657
- [整洁架构](#整洁架构)
5758

59+
## 领域
60+
61+
模板包含三个完整实现的领域,每个领域均可通过所有四种传输协议(REST、gRPC、AMQP RPC、NATS RPC)访问。
62+
63+
### 用户认证
64+
65+
注册、登录和基于 JWT 的授权。
66+
67+
| 操作 | REST | gRPC |
68+
|------|--------------------------|--------------------------|
69+
| 注册 | `POST /v1/auth/register` | `AuthService/Register` |
70+
| 登录 | `POST /v1/auth/login` | `AuthService/Login` |
71+
| 获取资料 | `GET /v1/user/profile` | `AuthService/GetProfile` |
72+
73+
- 密码使用 bcrypt 加密
74+
- JWT 令牌支持可配置的过期时间
75+
- 所有传输协议均有认证中间件
76+
77+
### 任务管理
78+
79+
CRUD 操作,支持状态状态机。
80+
81+
| 操作 | REST | gRPC |
82+
|------|------------------------------|------------------------------|
83+
| 创建 | `POST /v1/tasks` | `TaskService/CreateTask` |
84+
| 列表 | `GET /v1/tasks` | `TaskService/ListTasks` |
85+
| 获取 | `GET /v1/tasks/:id` | `TaskService/GetTask` |
86+
| 更新 | `PUT /v1/tasks/:id` | `TaskService/UpdateTask` |
87+
| 状态转换 | `PATCH /v1/tasks/:id/status` | `TaskService/TransitionTask` |
88+
| 删除 | `DELETE /v1/tasks/:id` | `TaskService/DeleteTask` |
89+
90+
- 状态转换:`todo``in_progress``done`(以及 `in_progress``todo`
91+
- 支持 `limit`/`offset` 分页和可选状态过滤
92+
- 任务绑定到已认证的用户
93+
94+
### 翻译
95+
96+
通过外部 API 进行文本翻译,支持历史记录。
97+
98+
| 操作 | REST | gRPC |
99+
|----|-------------------------------------|-----------------------------------------|
100+
| 翻译 | `POST /v1/translation/do-translate` | `TranslationHistoryService/DoTranslate` |
101+
| 历史 | `GET /v1/translation/history` | `TranslationHistoryService/ShowHistory` |
102+
58103
## Quick start
59104

60105
### Local development
@@ -162,9 +207,10 @@ go run -tags migrate ./cmd/app
162207

163208
### `internal/controller`
164209

165-
服务器处理层(MVC 控制器)。模板展示了 3 种服务器:
210+
服务器处理层(MVC 控制器)。模板展示了 4 种服务器:
166211

167212
- AMQP RPC(基于 RabbitMQ 作为传输)
213+
- NATS RPC(基于 NATS 作为传输)
168214
- gRPC(基于 protobuf 的 [gRPC](https://grpc.io/) 框架)
169215
- REST API(基于 [Fiber](https://github.com/gofiber/fiber) 框架)
170216

@@ -184,7 +230,7 @@ go run -tags migrate ./cmd/app
184230
routes := make(map[string]server.CallHandler)
185231

186232
{
187-
v1.NewTranslationRoutes(routes, t, l)
233+
v1.NewRoutes(routes, t, u, tk, j, l)
188234
}
189235

190236
{
@@ -201,10 +247,14 @@ routes := make(map[string]server.CallHandler)
201247

202248
```go
203249
{
250+
v1.NewAuthRoutes(app, u, l)
251+
v1.NewTaskRoutes(app, tk, l)
204252
v1.NewTranslationRoutes(app, t, l)
205253
}
206254

207255
{
256+
v2.NewAuthRoutes(app, u, l)
257+
v2.NewTaskRoutes(app, tk, l)
208258
v2.NewTranslationRoutes(app, t, l)
209259
}
210260

@@ -221,7 +271,7 @@ reflection.Register(app)
221271
routes := make(map[string]server.CallHandler)
222272

223273
{
224-
v1.NewTranslationRoutes(routes, t, l)
274+
v1.NewRoutes(routes, t, u, tk, j, l)
225275
}
226276

227277
{
@@ -238,11 +288,11 @@ routes := make(map[string]server.CallHandler)
238288
```go
239289
apiV1Group := app.Group("/v1")
240290
{
241-
v1.NewTranslationRoutes(apiV1Group, t, l)
291+
v1.NewRoutes(apiV1Group, t, u, tk, jwtManager, l)
242292
}
243293
apiV2Group := app.Group("/v2")
244294
{
245-
v2.NewTranslationRoutes(apiV2Group, t, l)
295+
v2.NewRoutes(apiV2Group, t, u, tk, jwtManager, l)
246296
}
247297
```
248298

@@ -289,7 +339,7 @@ RabbitMQ RPC 模式:
289339
这使得业务逻辑独立(且可移植)
290340
我们可以覆盖接口的实现,而无需更改 `usecase` 包.
291341

292-
它还将允许我们自动生成相关mock(例如使用 [mockery](https://github.com/vektra/mockery)),以便进行单元测试.
342+
它还将允许我们自动生成相关mock(例如使用 [go.uber.org/mock](https://go.uber.org/mock)),以便进行单元测试.
293343
> 我们不依赖于特定的实现,以便始终能够将一个组件更改为另一个组件
294344
> 如果新组件实现了接口,则业务逻辑无需更改。
295345
@@ -395,8 +445,8 @@ HTTP 和数据库都在外层,这意味着他们彼此无法感知
395445

396446
- **Use Cases** 业务逻辑位于 `internal/usecase`
397447
与业务逻辑直接交互的层通常称为_infrastructure_
398-
这些可以是存储库 `internal/usecase/repo`、外部 webapi `internal/usecase/webapi`、任何包和其他微服务。
399-
在模板中,_infrastructure_ 包位于 `internal/usecase`
448+
这些可以是存储库 `internal/repo/persistent`、外部 webapi `internal/repo/webapi`、任何包和其他微服务。
449+
在模板中,_infrastructure_ 包位于 `internal/repo`
400450

401451
您可以根据需要决定你要调用的入口点,包括:
402452

0 commit comments

Comments
 (0)