Skip to content

Commit 50ba35a

Browse files
committed
update document
1 parent e10968a commit 50ba35a

File tree

6 files changed

+48
-35
lines changed

6 files changed

+48
-35
lines changed

.github/RELEASE.md

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
## Change log
22

3-
- Added generate database initialization code command.
4-
- Added support for postgresql, tidb, sqlite generation code.
5-
- Modify the Sponge UI interface.
6-
- Adjust database configuration in configuration.
7-
- Added generate k8s configmap script command.
8-
- The generated code version matches the local sponge version.
9-
- Fixed redundant createdAt and updatedAt fields in service and handler.
10-
- Add encryption and decryption library.
11-
- Add scheduled task library.
3+
- Add model, dao, handler, service, web service, and grpc service code generated from mongodb sql.
4+
- Add test generation code command script.
5+
- Update document.

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ image-build-rpc-test:
169169

170170

171171
.PHONY: patch
172-
# patch some dependent code, such as types.proto, mysql initialization code. e.g. make patch TYPE=types-pb , make patch TYPE=init-your_db_driver, replace "your_db_driver" with mysql, postgresql, tidb, sqlite
172+
# patch some dependent code, such as types.proto, mysql initialization code. e.g. make patch TYPE=types-pb , make patch TYPE=init-your_db_driver, replace "your_db_driver" with mysql, mongodb, postgresql, tidb, sqlite
173173
patch:
174174
@bash scripts/patch.sh $(TYPE)
175175

README.md

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
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 Go code to compile and deploy to servers, dockers, k8s, and the complete service code is generated by sponge.
22+
If you are develop RESTful web service or microservice with a simple CRUD API interface, you don't need to write any Go code can be compiled and deployed to the linux server, docker, k8s, just need to connect to the database (mysql、mongodb、postgresql、tidb、sqlite) to generate a complete service code.
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 Go codes are generated by sponge.
24+
If you develop generic web or microservices, just focus on the three core parts of `define database tables`, `define api interfaces in proto files`, `fill in business logic code in the generated template files`, and the rest of the go code is automatically generated by sponge.
2525

2626
<br>
2727

2828
### 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. `SQL` supports databases **mysql**, **postgresql**, **tidb**, **sqlite**.
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**, **mongodb**, **postgresql**, **tidb**, **sqlite**.
3131

3232
#### Generate Code Framework
3333

@@ -47,9 +47,9 @@ sponge is mainly based on `SQL` and `Protobuf` two ways to generate code, each w
4747

4848
#### Generate Code for Egg Model
4949

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:
50+
The sponge code generation process strips away the business logic and non-business logic of the two major parts of the code. Sponge's code generation function as a hen, the generated service code is the egg, take the generated web service backend code as an example:
5151

52-
- `Eggshell` represents the web service framework code, `yolk` and `Albumen` both represent the business logic code.
52+
- `Eggshell` is web service framework code (automatically generated without manual writing).
5353
- `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).
5454
- `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).
5555

@@ -75,9 +75,6 @@ Sponge is essentially a microservice framework that includes code generation cap
7575

7676
### Key Features
7777

78-
- User-friendly UI for code generation commands.
79-
- Not only generate code template examples, but also automatically merge the new template code to achieve api interface "low-code development".
80-
- Modular and decoupled code design with rich functional components readily available, you can also easily use their own components.
8178
- Web framework [gin](https://github.com/gin-gonic/gin)
8279
- RPC framework [grpc](https://github.com/grpc/grpc-go)
8380
- Configuration parsing [viper](https://github.com/spf13/viper)
@@ -115,23 +112,23 @@ The project code directory structure created by sponge follows the [project-layo
115112
│ ├── initial # Program initialization, consisting of three files: initApp initializes configurations, registerServers registers services (HTTP or grpc), and registerClose registers resource cleanup.
116113
│ └── main.go # Program entry file
117114
├── configs # Directory for configuration files
118-
├── deployments # Directory for deployment scripts, supporting binary, Docker, and Kubernetes deployments.
115+
├── deployments # Directory for deployment scripts, supporting binary, Docker and Kubernetes deployments.
119116
├─ docs # Directory for API interface Swagger documentation.
120117
├── internal # Directory for code of private applications and libraries.
121118
│ ├── cache # Cache directory wrapped around business logic.
122119
│ ├── config # Directory for Go structure configuration files.
123-
│ ├── dao # Data access directory, e.g., interfaces for CRUD operations on MySQL tables.
120+
│ ├── dao # Data access directory.
124121
│ ├── ecode # Directory for system error codes and custom business error codes.
125122
│ ├── handler # Directory for implementing HTTP business functionality (specific to web services).
126123
│ ├── model # Database model directory.
127124
│ ├── routers # HTTP routing directory.
128125
│ ├── rpcclient # Directory for client-side code that connects to grpc services.
129126
│ ├── server # Directory for creating services, including HTTP and grpc.
130-
│ ├── service # Directory for implementing grpc business functionality (specific to microservices).
127+
│ ├── service # Directory for implementing grpc business functionality (specific to grpc services).
131128
│ └── types # Directory for defining request and response parameter structures for HTTP.
132129
├── pkg # Directory for shared libraries.
133130
├── scripts # Directory for scripts, including compilation, execution, code generation, and deployment scripts.
134-
├── test # Directory for scripts required for testing services, such as scripts to start dependencies (e.g., MySQL, Redis) and test data (SQL).
131+
├── test # Directory for scripts required for testing services and test SQL.
135132
└── third_party # Directory for external helper programs, forked code, and other third-party tools.
136133
```
137134

assets/readme-cn.md

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11

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

44
<br>
55

6-
如果开发只有简单CRUD api接口的web或微服务,不需要编写一行go代码就可以编译并部署到服务器、docker、k8s上,完整的服务代码由sponge一键生成
6+
如果开发只有简单CRUD api接口的web或微服务,不需要编写任何go代码就可以编译并部署到linux服务器、docker、k8s上,只需要连接到数据库(mysql、mongodb、postgresql、tidb、sqlite)就可以一键自动生成完整的服务代码
77

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

1010
<br>
1111

1212
### 生成代码框架
1313

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

1616
#### 生成代码的框架图
1717

@@ -31,10 +31,10 @@ sponge主要基于`SQL`和`Protobuf`两种方式生成代码,每种方式拥
3131

3232
#### 生成代码的鸡蛋模型
3333

34-
sponge生成代码过程中剥离了业务逻辑与非业务逻辑两大部分代码,把sponge生成的一个完整web服务后端代码看作是一个完整的鸡蛋
34+
sponge生成代码过程中剥离了业务逻辑与非业务逻辑两大部分代码,把sponge的生成代码功能看作是母鸡,生成的服务代码就是鸡蛋,以生成的一个web服务后端代码为例
3535

36-
- `蛋壳`表示web服务框架代码,`蛋白``蛋黄`都表示业务逻辑代码
37-
- `蛋黄`是业务逻辑的核心,例如定义mysql表、定义api接口、编写具体逻辑代码都属于蛋黄部分(需要人工编写的代码)。
36+
- `蛋壳`是web服务框架代码(自动生成,不需要人工编写)
37+
- `蛋黄`是业务逻辑的核心,例如定义mysql表、在proto定义api接口、编写具体逻辑代码都属于蛋黄部分(需要人工编写的代码)。
3838
- `蛋白`是业务逻辑核心代码与web框架代码连接的桥梁,例如根据proto文件生成的注册路由代码、handler代码、dao代码、参数校验代码、错误码、swagger文档等都属于蛋白部分(自动生成,不需要人工编写)。
3939

4040
下面是`⓷基于protobuf创建的web服务`代码的鸡蛋模型剖析图:
@@ -61,9 +61,6 @@ sponge本质是一个包含了生成代码功能的微服务框架,微服务
6161

6262
sponge包含丰富的组件(按需使用):
6363

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

configs/serverNameExample.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ database:
8888
driver: "mysql" # database driver, currently support mysql, postgres, tidb, sqlite
8989
# mysql settings
9090
mysql:
91-
# dsn format, <user>:<pass>@(127.0.0.1:3306)/<db>?[k=v& ......]
91+
# dsn format, <username>:<password>@(<hostname>:<port>)/<db>?[k=v& ......]
9292
dsn: "root:123456@(192.168.3.37:3306)/account?parseTime=true&loc=Local&charset=utf8,utf8mb4"
9393
enableLog: true # whether to turn on printing of all logs
9494
maxIdleConns: 10 # set the maximum number of connections in the idle connection pool
@@ -102,7 +102,7 @@ database:
102102

103103
# postgresql settings
104104
postgresql:
105-
# dsn format, <user>:<pass>@127.0.0.1:5432/<db>?[k=v& ......]
105+
# dsn format, <username>:<password>@<hostname>:<port>/<db>?[k=v& ......]
106106
dsn: "root:123456@192.168.3.37:5432/account?sslmode=disable"
107107
enableLog: true # whether to turn on printing of all logs
108108
maxIdleConns: 10 # set the maximum number of connections in the idle connection pool
@@ -117,6 +117,12 @@ database:
117117
maxOpenConns: 100 # set the maximum number of open database connections
118118
connMaxLifetime: 10 # sets the maximum time for which the connection can be reused, in minutes
119119

120+
# mongodb settings
121+
mongodb:
122+
# dsn format, <username>:<password>@<hostname1>:<port1>[,<hostname2>:<port2>,......]/<db>?[k=v& ......]
123+
# parameter k=v see https://www.mongodb.com/docs/drivers/go/current/fundamentals/connections/connection-guide/#connection-options
124+
dsn: "root:123456@192.168.3.37:27017/account?connectTimeoutMS=15000"
125+
120126
# delete the templates code end
121127

122128
# redis settings

scripts/patch.sh

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
patchType=$1
44
typesPb="types-pb"
55
initMysql="init-mysql"
6+
initMongodb="init-mongodb"
67
initTidb="init-tidb"
78
initPostgresql="init-postgresql"
9+
initSqlite="init-sqlite"
810

911
function checkResult() {
1012
result=$1
@@ -28,6 +30,12 @@ function generateInitMysqlCode() {
2830
importPkg
2931
}
3032

33+
function generateInitMongodbCode() {
34+
sponge patch gen-db-init --db-driver=mongodb --out=./
35+
checkResult $?
36+
importPkg
37+
}
38+
3139
function generateInitTidbCode() {
3240
sponge patch gen-db-init --db-driver=tidb --out=./
3341
checkResult $?
@@ -40,17 +48,28 @@ function generateInitPostgresqlCode() {
4048
importPkg
4149
}
4250

51+
function generateInitSqliteCode() {
52+
sponge patch gen-db-init --db-driver=sqlite --out=./
53+
checkResult $?
54+
importPkg
55+
}
56+
4357
if [ "$patchType" = "$typesPb" ]; then
4458
generateTypesPbCode
4559
elif [ "$patchType" = "$initMysql" ]; then
4660
generateInitMysqlCode
61+
elif [ "$patchType" = "$initMongodb" ]; then
62+
generateInitMongodbCode
4763
elif [ "$patchType" = "$initTidb" ]; then
4864
generateInitTidbCode
4965
elif [ "$patchType" = "$initPostgresql" ]; then
5066
generateInitPostgresqlCode
67+
elif [ "$patchType" = "$initSqlite" ]; then
68+
generateInitSqliteCode
5169
else
5270
echo "invalid patch type: '$patchType'"
53-
echo "supported types: $initMysql, $initTidb, $initPostgresql, $typesPb"
71+
echo "supported types: $initMysql, $initMongodb, $initTidb, $initPostgresql, $initSqlite, $typesPb"
5472
echo "e.g. make patch TYPE=init-mysql"
73+
echo ""
5574
exit 1
5675
fi

0 commit comments

Comments
 (0)