Skip to content

Commit 0ca5eaf

Browse files
committed
update docs
1 parent 95c77b0 commit 0ca5eaf

File tree

9 files changed

+52
-46
lines changed

9 files changed

+52
-46
lines changed

.github/RELEASE.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@
77
- Added generate k8s configmap script command.
88
- The generated code version matches the local sponge version.
99
- Fixed redundant createdAt and updatedAt fields in service and handler.
10+
- Add encryption and decryption library.
11+
- Add scheduled task library.

README.md

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,60 +19,64 @@
1919

2020
<br>
2121

22-
If you are developing a RESTful web service or microservice with a simple CRUD API interface, you don't need to write a single line of golang code to compile and deploy to servers, dockers, k8s, and the complete service code is generated by sponge.
22+
If you are developing a RESTful web service or microservice with a simple CRUD API interface, you don't need to write a single line of Go code to compile and deploy to servers, dockers, k8s, and the complete service code is generated by sponge.
2323

24-
If you develop a generic RESTful web service or microservice, you need to manually write code in addition to defining the data table, defining the api interface in the proto file, and filling in the specific business logic code in the generated template file. Other golang codes are generated by sponge.
24+
If you develop a generic RESTful web service or microservice, you need to manually write code in addition to defining the data table, defining the api interface in the proto file, and filling in the specific business logic code in the generated template file. Other Go codes are generated by sponge.
2525

2626
<br>
2727

28-
### sponge generates the code framework
28+
### Sponge Generates the Code Framework
2929

30-
sponge is mainly based on **SQL** and **Protobuf** two ways to generate code, each way has to generate code for different functions.
30+
sponge is mainly based on `SQL` and `Protobuf` two ways to generate code, each way has to generate code for different functions. `SQL` supports databases **mysql**, **postgresql**, **tidb**, **sqlite**.
3131

32-
**Generate code framework:**
32+
#### Generate Code Framework
3333

3434
<p align="center">
3535
<img width="1500px" src="https://raw.githubusercontent.com/zhufuyi/sponge/main/assets/sponge-framework.png">
3636
</p>
3737

3838
<br>
3939

40-
**Generate code framework corresponding UI interface:**
40+
#### Generate Code Framework Corresponding UI Interface
4141

4242
<p align="center">
4343
<img width="1200px" src="https://raw.githubusercontent.com/zhufuyi/sponge/main/assets/en_sponge-ui.png">
4444
</p>
4545

4646
<br>
4747

48-
### Services framework
48+
#### Generate Code for Egg Model
49+
50+
The sponge code generation process strips away the business logic and non-business logic of the two major parts of the code, sponge generated a complete web service back-end code as a complete egg:
51+
52+
- `Eggshell` represents the web service framework code, `yolk` and `Albumen` both represent the business logic code.
53+
- `Yolk` is the core of business logic. For example, defining mysql tables, defining api interfaces, and writing specific logic codes all belong to yolk (code that needs to be written manually).
54+
- `Albumen` is a bridge connecting the core code of business logic and the web framework code. For example, the registration route code, handler code, parameter verification code, error code, and swagger document generated according to the proto file belong to the albumen (code that automatically generated without manual writing).
4955

50-
Sponge is essentially a microservice framework that includes code generation and deployment capabilities. The microservice framework is shown in the following figure, which is a typical microservice hierarchical structure, with high performance, high scalability, contains commonly used service governance features, you can easily replace or add their own service governance features.
56+
Here is egg model profiling diagram for `⓷Create web service based on protobuf`:
5157

5258
<p align="center">
53-
<img width="1000px" src="https://raw.githubusercontent.com/zhufuyi/sponge/main/assets/microservices-framework.png">
59+
<img width="1200px" src="https://raw.githubusercontent.com/zhufuyi/sponge_examples/main/assets/en_web-http-pb-anatomy.png">
5460
</p>
5561

56-
<br>
62+
In addition to the egg model of web service backend code, there are egg models of grpc service code and grpc gateway service code described in [sponge documentation](https://go-sponge.com/learn-about-sponge?id=%f0%9f%8f%b7project-code-egg-model).
5763

58-
### Egg model of a web service code generated by sponge
64+
<br>
5965

60-
The sponge separates the two major parts of code during the process of generating web service code. It isolates the business logic from the non-business logic. For example, consider the entire web service code as an egg. The eggshell represents the web service framework code, while both the albumen and yolk represent the business logic code. The yolk is the core of the business logic (manually written code). It includes defining MySQL tables, defining API interfaces, and writing specific logic code.On the other hand, the albumen acts as a bridge connecting the core business logic code to the web framework code (automatically generated, no manual writing needed). This includes the registration of route code generated from proto files, handler method function code, parameter validation code, error codes, Swagger documentation, and more.
66+
### Services framework
6167

62-
Egg model profiling diagram for `⓷Web services created based on protobuf`:
68+
Sponge is essentially a microservice framework that includes code generation capabilities. The microservice framework is shown in the following figure, which is a typical microservice hierarchical structure, with high performance, high scalability, contains commonly used service governance features, you can easily replace or add their own service governance features.
6369

6470
<p align="center">
65-
<img width="1200px" src="https://raw.githubusercontent.com/zhufuyi/sponge_examples/main/assets/en_web-http-pb-anatomy.png">
71+
<img width="1000px" src="https://raw.githubusercontent.com/zhufuyi/sponge/main/assets/microservices-framework.png">
6672
</p>
6773

68-
This is the egg model for web service code, and there are egg models for grpc service code, and grpc gateway service code described in [sponge documentation](https://go-sponge.com/learn-about-sponge?id=%f0%9f%8f%b7project-code-egg-model).
69-
7074
<br>
7175

7276
### Key Features
7377

7478
- User-friendly UI for code generation commands.
75-
- Automatic merging of template code for "low-code development" of API interfaces.
79+
- Not only generate code template examples, but also automatically merge the new template code to achieve api interface "low-code development".
7680
- Modular and decoupled code design with rich functional components readily available, you can also easily use their own components.
7781
- Web framework [gin](https://github.com/gin-gonic/gin)
7882
- RPC framework [grpc](https://github.com/grpc/grpc-go)

assets/en_sponge-ui.png

15.5 KB
Loading

assets/readme-cn.md

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,68 @@
11

2-
3-
42
[sponge](https://github.com/zhufuyi/sponge) 是一个集成了 `自动生成代码``Gin和GRPC` 的基础开发框架。sponge拥有丰富的生成代码命令,生成不同的功能代码可以组合成完整的服务(类似人为打散的海绵细胞可以自动重组成一个新的海绵)。代码解耦模块化设计,很容易构建出从开发到部署的完整工程项目,只需在生成的模板代码上填充具体业务逻辑代码,极大的提高了开发效率和降低了开发难度,使用go也可以"低代码开发"。
53

64
<br>
75

8-
如果开发只有简单CRUD api接口的web或微服务,不需要编写一行golang代码就可以编译并部署到服务器、docker、k8s上,完整的服务代码由sponge一键生成。
6+
如果开发只有简单CRUD api接口的web或微服务,不需要编写一行go代码就可以编译并部署到服务器、docker、k8s上,完整的服务代码由sponge一键生成。
97

10-
如果开发通用的web或微服务,除了定义数据表、在proto文件定义api接口、在生成的模板文件填写具体业务逻辑代码这三个部分需要人工编写代码,其他golang代码都由sponge生成
8+
如果开发通用的web或微服务,除了`定义数据库表``在proto文件定义api接口``在生成的模板文件填写业务逻辑代码`这三个部分需要人工编写,其他go代码都由sponge生成
119

1210
<br>
1311

1412
### 生成代码框架
1513

16-
sponge主要基于**SQL****Protobuf**两种方式生成代码,每种方式拥有生成不同功能代码
14+
sponge主要基于`SQL``Protobuf`两种方式生成代码,每种方式拥有生成不同用途的代码。其中`SQL`支持数据库**mysql****postgresql****tidb****sqlite**
1715

18-
**生成代码的框架图**
16+
#### 生成代码的框架图
1917

2018
<p align="center">
2119
<img width="1500px" src="https://raw.githubusercontent.com/zhufuyi/sponge/main/assets/sponge-framework.png">
2220
</p>
2321

2422
<br>
2523

26-
**生成代码框架对应的UI界面**
24+
#### 生成代码框架对应的UI界面
2725

2826
<p align="center">
2927
<img width="1500px" src="https://raw.githubusercontent.com/zhufuyi/sponge/main/assets/sponge-ui.png">
3028
</p>
3129

3230
<br>
3331

34-
### 微服务框架
32+
#### 生成代码的鸡蛋模型
33+
34+
sponge生成代码过程中剥离了业务逻辑与非业务逻辑两大部分代码,把sponge生成的一个完整web服务后端代码看作是一个完整的鸡蛋:
3535

36-
sponge本质是一个包含了生成代码和部署功能的微服务框架,微服务框架如下图所示,这是典型的微服务分层结构,具有高性能,高扩展性,包含了常用的服务治理功能,可以很方便替换或添加自己的服务治理功能。
36+
- `蛋壳`表示web服务框架代码,`蛋白``蛋黄`都表示业务逻辑代码。
37+
- `蛋黄`是业务逻辑的核心,例如定义mysql表、定义api接口、编写具体逻辑代码都属于蛋黄部分(需要人工编写的代码)。
38+
- `蛋白`是业务逻辑核心代码与web框架代码连接的桥梁,例如根据proto文件生成的注册路由代码、handler代码、dao代码、参数校验代码、错误码、swagger文档等都属于蛋白部分(自动生成,不需要人工编写)。
39+
40+
下面是`⓷基于protobuf创建的web服务`代码的鸡蛋模型剖析图:
3741

3842
<p align="center">
39-
<img width="1000px" src="https://raw.githubusercontent.com/zhufuyi/sponge/main/assets/microservices-framework.png">
43+
<img width="1200px" src="https://raw.githubusercontent.com/zhufuyi/sponge_examples/main/assets/web-http-pb-anatomy.png">
4044
</p>
4145

42-
<br>
46+
除了web服务后端代码鸡蛋模型,还有grpc服务代码、grpc网关服务代码的鸡蛋模型,在[sponge文档](https://go-sponge.com/zh-cn/learn-about-sponge?id=%f0%9f%8f%b7%e9%a1%b9%e7%9b%ae%e4%bb%a3%e7%a0%81%e9%b8%a1%e8%9b%8b%e6%a8%a1%e5%9e%8b)中有介绍。
4347

44-
### sponge生成的一个web服务代码的鸡蛋模型
48+
<br>
4549

46-
sponge生成代码过程中剥离了业务逻辑与非业务逻辑两大部分代码。例如把一个完整web服务代码看作一个鸡蛋,蛋壳表示web服务框架代码,蛋白和蛋黄都表示业务逻辑代码,蛋黄是业务逻辑的核心(需要人工编写的代码),例如定义mysql表、定义api接口、编写具体逻辑代码都属于蛋黄部分。蛋白是业务逻辑核心代码与web框架代码连接的桥梁(自动生成,不需要人工编写),例如根据proto文件生成的注册路由代码、handler方法函数代码、参数校验代码、错误码、swagger文档等都属于蛋白部分。
50+
### 微服务框架
4751

48-
`⓷基于protobuf创建的web服务`代码的鸡蛋模型剖析图:
52+
sponge本质是一个包含了生成代码功能的微服务框架,微服务框架如下图所示,这是典型的微服务分层结构,具有高性能,高扩展性,包含了常用的服务治理功能,可以很方便替换或添加自己的服务治理功能。
4953

5054
<p align="center">
51-
<img width="1200px" src="https://raw.githubusercontent.com/zhufuyi/sponge_examples/main/assets/web-http-pb-anatomy.png">
55+
<img width="1000px" src="https://raw.githubusercontent.com/zhufuyi/sponge/main/assets/microservices-framework.png">
5256
</p>
5357

54-
这是web服务代码鸡蛋模型,还有grpc服务代码、grpc网关服务代码的鸡蛋模型在[sponge文档](https://go-sponge.com/zh-cn/learn-about-sponge?id=%f0%9f%8f%b7%e9%a1%b9%e7%9b%ae%e4%bb%a3%e7%a0%81%e9%b8%a1%e8%9b%8b%e6%a8%a1%e5%9e%8b)中有介绍。
55-
5658
<br>
5759

5860
### 主要功能
5961

6062
sponge包含丰富的组件(按需使用):
6163

6264
- 生成代码命令UI界面化,简单易用。
63-
- 自动合并新增模板代码,实现api接口"低代码开发"。
65+
- 不仅生成代码模板示例,而且自动合并新增模板代码,实现api接口"低代码开发"。
6466
- 代码解耦模块化设计,丰富功能组件开箱即用,也可以很方便使用自己的组件。
6567
- Web 框架 [gin](https://github.com/gin-gonic/gin)
6668
- RPC 框架 [grpc](https://github.com/grpc/grpc-go)

assets/sponge-ui.png

14.3 KB
Loading

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ require (
2929
github.com/pkg/errors v0.9.1
3030
github.com/prometheus/client_golang v1.13.0
3131
github.com/rabbitmq/amqp091-go v1.9.0
32+
github.com/robfig/cron/v3 v3.0.1
3233
github.com/shirou/gopsutil/v3 v3.23.8
3334
github.com/spf13/cobra v1.4.0
3435
github.com/spf13/viper v1.12.0
@@ -47,6 +48,7 @@ require (
4748
go.opentelemetry.io/otel/sdk v1.9.0
4849
go.opentelemetry.io/otel/trace v1.9.0
4950
go.uber.org/zap v1.21.0
51+
golang.org/x/crypto v0.14.0
5052
golang.org/x/sync v0.1.0
5153
google.golang.org/genproto v0.0.0-20230223222841-637eb2293923
5254
google.golang.org/grpc v1.53.0
@@ -170,7 +172,6 @@ require (
170172
go.uber.org/atomic v1.7.0 // indirect
171173
go.uber.org/multierr v1.6.0 // indirect
172174
golang.org/x/arch v0.3.0 // indirect
173-
golang.org/x/crypto v0.14.0 // indirect
174175
golang.org/x/net v0.10.0 // indirect
175176
golang.org/x/oauth2 v0.5.0 // indirect
176177
golang.org/x/sys v0.13.0 // indirect

go.sum

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,8 @@ github.com/prometheus/procfs v0.8.0 h1:ODq8ZFEaYeCaZOJlZZdJA2AbQR98dSHSM1KW/You5
579579
github.com/prometheus/procfs v0.8.0/go.mod h1:z7EfXMXOkbkqb9IINtpCn86r/to3BnA0uaxHdg830/4=
580580
github.com/rabbitmq/amqp091-go v1.9.0 h1:qrQtyzB4H8BQgEuJwhmVQqVHB9O4+MNDJCCAcpc3Aoo=
581581
github.com/rabbitmq/amqp091-go v1.9.0/go.mod h1:+jPrT9iY2eLjRaMSRHUhc3z14E/l85kv/f+6luSD3pc=
582+
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
583+
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
582584
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
583585
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
584586
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
@@ -1175,15 +1177,11 @@ gorm.io/driver/postgres v1.5.4 h1:Iyrp9Meh3GmbSuyIAGyjkN+n9K+GHX9b9MqsTL4EJCo=
11751177
gorm.io/driver/postgres v1.5.4/go.mod h1:Bgo89+h0CRcdA33Y6frlaHHVuTdOf87pmyzwW9C/BH0=
11761178
gorm.io/driver/sqlite v1.5.4 h1:IqXwXi8M/ZlPzH/947tn5uik3aYQslP9BVveoax0nV0=
11771179
gorm.io/driver/sqlite v1.5.4/go.mod h1:qxAuCol+2r6PannQDpOP1FP6ag3mKi4esLnB/jHed+4=
1178-
gorm.io/driver/sqlite v1.5.5 h1:7MDMtUZhV065SilG62E0MquljeArQZNfJnjd9i9gx3E=
1179-
gorm.io/driver/sqlite v1.5.5/go.mod h1:6NgQ7sQWAIFsPrJJl1lSNSu2TABh0ZZ/zm5fosATavE=
11801180
gorm.io/gorm v1.23.8/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk=
11811181
gorm.io/gorm v1.25.1/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
11821182
gorm.io/gorm v1.25.2/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
11831183
gorm.io/gorm v1.25.5 h1:zR9lOiiYf09VNh5Q1gphfyia1JpiClIWG9hQaxB/mls=
11841184
gorm.io/gorm v1.25.5/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
1185-
gorm.io/gorm v1.25.7-0.20240204074919-46816ad31dde h1:9DShaph9qhkIYw7QF91I/ynrr4cOO2PZra2PFD7Mfeg=
1186-
gorm.io/gorm v1.25.7-0.20240204074919-46816ad31dde/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
11871185
gorm.io/plugin/dbresolver v1.4.7 h1:ZwtwmJQxTx9us7o6zEHFvH1q4OeEo1pooU7efmnunJA=
11881186
gorm.io/plugin/dbresolver v1.4.7/go.mod h1:l4Cn87EHLEYuqUncpEeTC2tTJQkjngPSD+lo8hIvcT0=
11891187
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

internal/dao/userExample.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,14 @@ func (d *userExampleDao) GetByID(ctx context.Context, id uint64) (*model.UserExa
152152
return record, err
153153
}
154154

155-
// get from cache or mysql
155+
// get from cache or database
156156
record, err := d.cache.Get(ctx, id)
157157
if err == nil {
158158
return record, nil
159159
}
160160

161161
if errors.Is(err, model.ErrCacheNotFound) {
162-
// for the same id, prevent high concurrent simultaneous access to mysql
162+
// for the same id, prevent high concurrent simultaneous access to database
163163
val, err, _ := d.sfg.Do(utils.Uint64ToStr(id), func() (interface{}, error) { //nolint
164164
table := &model.UserExample{}
165165
err = d.db.WithContext(ctx).Where("id = ?", id).First(table).Error
@@ -249,7 +249,7 @@ func (d *userExampleDao) GetByIDs(ctx context.Context, ids []uint64) (map[uint64
249249
return itemMap, nil
250250
}
251251

252-
// get form cache or mysql
252+
// get form cache or database
253253
itemMap, err := d.cache.MultiGet(ctx, ids)
254254
if err != nil {
255255
return nil, err
@@ -266,7 +266,7 @@ func (d *userExampleDao) GetByIDs(ctx context.Context, ids []uint64) (map[uint64
266266

267267
// get missed data
268268
if len(missedIDs) > 0 {
269-
// find the id of an active placeholder, i.e. an id that does not exist in mysql
269+
// find the id of an active placeholder, i.e. an id that does not exist in database
270270
var realMissedIDs []uint64
271271
for _, id := range missedIDs {
272272
_, err = d.cache.Get(ctx, id)

internal/handler/userExample.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,7 @@ func (h *userExampleHandler) ListByIDs(c *gin.Context) {
286286
err := c.ShouldBindJSON(form)
287287
if err != nil {
288288
logger.Warn("ShouldBindJSON error: ", logger.Err(err), middleware.GCtxRequestIDField(c))
289-
response.Error(c, ecode.InvalidParams.WithOutMsg("参数错误"), "详细错误信息")
290-
response.Output(c, ecode.Unauthorized.WithOutMsg("错误简单描述").ToHTTPCode(), "详细错误信息")
289+
response.Error(c, ecode.InvalidParams)
291290
return
292291
}
293292

0 commit comments

Comments
 (0)