docs: update readme

This commit is contained in:
zhuyasen
2025-01-08 19:45:53 +08:00
parent e7dcb143dd
commit ad8c295e5d
4 changed files with 198 additions and 183 deletions

105
README.md
View File

@@ -9,24 +9,27 @@
[![Go Report](https://goreportcard.com/badge/github.com/go-dev-frame/sponge)](https://goreportcard.com/report/github.com/go-dev-frame/sponge)
[![codecov](https://codecov.io/gh/go-dev-frame/sponge/branch/main/graph/badge.svg)](https://codecov.io/gh/go-dev-frame/sponge)
[![Go Reference](https://pkg.go.dev/badge/github.com/go-dev-frame/sponge.svg)](https://pkg.go.dev/github.com/go-dev-frame/sponge)
[![Go](https://github.com/go-dev-frame/sponge/workflows/Go/badge.svg?branch=main)](https://github.com/go-dev-frame/sponge/actions)
[![Go](https://github.com/go-dev-frame/sponge/workflows/Go/badge.svg)](https://github.com/go-dev-frame/sponge/actions)
[![Awesome Go](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/avelino/awesome-go)
[![License: MIT](https://img.shields.io/github/license/go-dev-frame/sponge)](https://img.shields.io/github/license/go-dev-frame/sponge)
</div>
**sponge** is a powerful `Go` development framework. Its core concept revolves around reverse-engineering modular code by parsing `JSON`, `SQL`, or `Protobuf` files. The generated code can be flexibly and seamlessly assembled into various types of complete backend services (similar to the characteristics of sponge cells, where disassembled sponge cells can automatically recombine into a new sponge). Sponge provides an all-in-one solution for project development, covering code generation, development, testing, API documentation, and deployment, significantly enhancing development efficiency, reducing complexity, and enabling high-quality projects with a "low-code approach".
**Sponge** is a powerful `Go` development framework. Its core concept revolves around reverse-engineering modular code by parsing `JSON`, `SQL`, or `Protobuf` files. The generated code can be flexibly and seamlessly assembled into various types of complete backend services (`similar to the characteristics of sponge cells, where disassembled sponge cells can automatically recombine into a new sponge`).
Sponge provides an all-in-one solution for project development, covering code generation, development, testing, API documentation, and deployment, significantly enhancing development efficiency, reducing complexity, and enabling high-quality projects with a "low-code approach".
<br>
### Use Cases
### Applicable scenarios
Sponge is suitable for quickly developing various high-performance backend services, including but not limited to:
- `Web` services (gin);
- `gRPC` services;
- `HTTP+gRPC` hybrid services;
- `gRPC Gateway API` services.
- `gRPC Gateway API` services;
- cloud-native microservices.
Additionally, developers can use custom templates to generate various types of code to meet specific business needs.
@@ -53,6 +56,8 @@ Additionally, developers can use custom templates to generate various types of c
- Test code;
- Build and deployment scripts, etc.
4. **Generate code on the page, simple and easy to use**
<br>
### Quick Start
@@ -79,54 +84,16 @@ Additionally, developers can use custom templates to generate various types of c
<br>
### Sponge Generates the Code Framework
### Main Features
Sponge supports generating code using both built-in templates and custom templates, as shown in the diagrams below.
1. The code generation framework based on Sponge's built-in templates is shown below. There are two approaches: SQL and Protobuf.
<p align="center">
<img width="1500px" src="https://raw.githubusercontent.com/go-dev-frame/sponge/main/assets/sponge-framework.png">
</p>
<br>
2. The code generation framework based on custom templates is shown below. There are three approaches: JSON, SQL, and Protobuf.
<p align="center">
<img width="1200px" src="https://raw.githubusercontent.com/go-dev-frame/sponge/main/assets/template-framework.png">
</p>
<br>
### Microservice framework
Sponge supports creating six types of backend services, all based on microservice architecture. The diagram below illustrates a typical layered microservice structure, featuring high performance, scalability, and built-in service governance capabilities.
<p align="center">
<img width="1000px" src="https://raw.githubusercontent.com/go-dev-frame/sponge/main/assets/microservices-framework.png">
</p>
<br>
Performance testing of http and grpc service code created by the microservices framework: 50 concurrent, 1 million total requests.
![http-server](https://raw.githubusercontent.com/zhufuyi/microservices_framework_benchmark/main/test/assets/http-server.png)
![grpc-server](https://raw.githubusercontent.com/zhufuyi/microservices_framework_benchmark/main/test/assets/grpc-server.png)
Click to view the [**test code**](https://github.com/zhufuyi/microservices_framework_benchmark).
<br>
### Key Features
Sponge has built-in rich features (for on-demand use):
- Web framework [gin](https://github.com/gin-gonic/gin)
- RPC framework [grpc](https://github.com/grpc/grpc-go)
- Configuration parsing [viper](https://github.com/spf13/viper)
- Logging component [zap](https://github.com/uber-go/zap)
- Database ORM component [gorm](https://github.com/go-gorm/gorm), [mongo-go-driver](https://github.com/mongodb/mongo-go-driver)
- Cache component [go-redis](https://github.com/go-redis/redis), [ristretto](https://github.com/dgraph-io/ristretto)
- ORM framework [gorm](https://github.com/go-gorm/gorm), [mongo-go-driver](https://github.com/mongodb/mongo-go-driver)
- Cache [go-redis](https://github.com/go-redis/redis), [ristretto](https://github.com/dgraph-io/ristretto)
- Automated API documentation [swagger](https://github.com/swaggo/swag), [protoc-gen-openapiv2](https://github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2)
- Authentication [jwt](https://github.com/golang-jwt/jwt)
- Websocket [gorilla/websocket](https://github.com/gorilla/websocket)
@@ -150,11 +117,53 @@ Click to view the [**test code**](https://github.com/zhufuyi/microservices_frame
<br>
### Generates Code Framework
Sponge supports generating code using both built-in templates and custom templates, as shown in the diagrams below.
1. The code generation framework based on Sponge's built-in templates is shown below. There are two approaches: SQL and Protobuf.
<p align="center">
<img width="1500px" src="https://raw.githubusercontent.com/go-dev-frame/sponge/main/assets/sponge-framework.png">
</p>
<br>
2. The code generation framework based on custom templates is shown below. There are three approaches: JSON, SQL, and Protobuf.
<p align="center">
<img width="1200px" src="https://raw.githubusercontent.com/go-dev-frame/sponge/main/assets/template-framework.png">
</p>
<br>
### Microservice framework
Five of the six types of back-end services created by sponge are microservice architectures. The diagram below illustrates a typical layered microservice structure, featuring high performance, scalability, and built-in service governance capabilities.
<p align="center">
<img width="1000px" src="https://raw.githubusercontent.com/go-dev-frame/sponge/main/assets/microservices-framework.png">
</p>
<br>
Performance testing of http and grpc service code created by the microservices framework: 50 concurrent, 1 million total requests.
![http-server](https://raw.githubusercontent.com/zhufuyi/microservices_framework_benchmark/main/test/assets/http-server.png)
![grpc-server](https://raw.githubusercontent.com/zhufuyi/microservices_framework_benchmark/main/test/assets/grpc-server.png)
Click to view the [**test code**](https://github.com/zhufuyi/microservices_framework_benchmark).
<br>
### Project Code Directory Structure
The project code directory structure created by sponge follows the [project-layout](https://github.com/golang-standards/project-layout).
Here is the directory structure for the generated `monolithic application single repository (monolith)` or `microservice multi-repository (multi-repo)` code:
Sponge supports creating three types of project code structures: `Monolithic application monorepo (monolith)`, `Microservices multi-repo (multi-repo)`, and `Microservices monorepo (mono-repo)`.
1. The code directory structure for creating a `Monolithic application monorepo (monolith)` or `Microservices multi-repo (multi-repo)` is as follows:
```bash
.
@@ -188,7 +197,7 @@ Here is the directory structure for the generated `monolithic application single
<br>
Here is the directory structure for the generated `microservice monolithic repository (mono-repo)` code (also known as large repository directory structure):
2. The code directory structure for creating a `Microservices monorepo (mono-repo)` (large repository code directory structure) is as follows:
```bash
.

View File

@@ -2,17 +2,18 @@
<br>
**sponge** 是一个强大的 `Go` 开发框架,其核心理念是通过解析 `JSON``SQL``Protobuf` 文件逆向生成模块化的代码,这些代码可以灵活、无缝地组合成多种类型的完整后端服务(类似海绵细胞的特性,打散的海绵细胞能自动重新组合成新的海绵)。sponge 提供一站式项目开发解决方案涵盖代码生成、开发、测试、API 文档生成和部署,大幅提升开发效率,降低开发难度,实现以"低代码"方式构建高质量项目。
**sponge** 是一个强大的 `Go` 开发框架,其核心理念是通过解析 `JSON``SQL``Protobuf` 文件逆向生成模块化的代码,这些代码可以灵活、无缝地组合成多种类型的完整后端服务`类似海绵细胞的特性,打散的海绵细胞能自动重新组合成新的海绵`。sponge 提供一站式项目开发解决方案涵盖代码生成、开发、测试、API 文档生成和部署,大幅提升开发效率,降低开发难度,实现以"低代码"方式构建高质量项目。
<br>
### 适用场景
sponge 适用于快速开发各种高性能后端服务,包括但不限于:
- `Web` 服务;
- `Web` 服务 (gin)
- `gRPC` 服务;
- `HTTP+gRPC` 混合服务;
- `gRPC Gateway API` 服务
- `gRPC Gateway API` 服务
- 云原生微服务;
此外,开发者还可以通过自定义模板,生成满足业务需求的各类代码。
@@ -39,6 +40,8 @@ sponge 适用于快速开发各种高性能后端服务,包括但不限于:
- 测试代码;
- 构建和部署脚本等。
4. **在页面生成代码,简单易用**
<br>
### 快速开始
@@ -65,62 +68,22 @@ sponge 适用于快速开发各种高性能后端服务,包括但不限于:
<br>
### 生成代码的框架图
sponge 支持基于自带模板和自定义模板两种方式生成你的项目所需的代码,下面是两种生成代码的框架图。
1. sponge 基于自带模板生成代码框架如下图所示,共有 sql 和 protobuf 两种方式生成代码。
<p align="center">
<img width="1500px" src="https://raw.githubusercontent.com/go-dev-frame/sponge/main/assets/sponge-framework.png">
</p>
<br>
2. sponge 基于自定义模板生成代码框架如下图所示,共有 json、sql、protobuf 三种方式生成代码。
<p align="center">
<img width="1200px" src="https://raw.githubusercontent.com/go-dev-frame/sponge/main/assets/template-framework.png">
</p>
<br>
### 微服务框架
sponge 支持创建 6 种类型的后端服务,均为微服务架构。下图展示了典型的微服务分层结构,具备高性能、高扩展性,并内置常用的服务治理功能。
<p align="center">
<img width="1000px" src="https://raw.githubusercontent.com/go-dev-frame/sponge/main/assets/microservices-framework.png">
</p>
<br>
创建的http和grpc服务代码的性能测试 50个并发总共100万个请求。
![http-server](https://raw.githubusercontent.com/zhufuyi/microservices_framework_benchmark/main/test/assets/http-server.png)
![grpc-server](https://raw.githubusercontent.com/zhufuyi/microservices_framework_benchmark/main/test/assets/grpc-server.png)
点击查看[**测试代码**](https://github.com/zhufuyi/microservices_framework_benchmark)。
<br>
### 主要功能
sponge包含丰富的组件(按需使用)
sponge 内置了丰富的功能(按需使用)
- Web 框架 [gin](https://github.com/gin-gonic/gin)
- RPC 框架 [grpc](https://github.com/grpc/grpc-go)
- 配置解析 [viper](https://github.com/spf13/viper)
- 日志 [zap](https://github.com/uber-go/zap)
- 数据库组件 [gorm](https://github.com/go-gorm/gorm), [mongo-go-driver](https://github.com/mongodb/mongo-go-driver)
- 缓存组件 [go-redis](https://github.com/go-redis/redis), [ristretto](https://github.com/dgraph-io/ristretto)
- ORM 框架 [gorm](https://github.com/go-gorm/gorm), [mongo-go-driver](https://github.com/mongodb/mongo-go-driver)
- 缓存 [go-redis](https://github.com/go-redis/redis), [ristretto](https://github.com/dgraph-io/ristretto)
- 自动化api文档 [swagger](https://github.com/swaggo/swag), [protoc-gen-openapiv2](https://github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2)
- 鉴权 [jwt](https://github.com/golang-jwt/jwt)
- 校验 [validator](https://github.com/go-playground/validator)
- Websocket [gorilla/websocket](https://github.com/gorilla/websocket)
- 定时任务 [cron](https://github.com/robfig/cron)
- 消息队列组件 [rabbitmq](https://github.com/rabbitmq/amqp091-go), [kafka](https://github.com/IBM/sarama)
- 消息队列 [rabbitmq](https://github.com/rabbitmq/amqp091-go), [kafka](https://github.com/IBM/sarama)
- 分布式事务管理器 [dtm](https://github.com/dtm-labs/dtm)
- 分布式锁 [dlock](https://github.com/go-dev-frame/sponge/tree/main/pkg/dlock)
- 自适应限流 [ratelimit](https://github.com/go-dev-frame/sponge/tree/main/pkg/shield/ratelimit)
@@ -138,11 +101,53 @@ sponge包含丰富的组件(按需使用)
<br>
### 生成代码的框架
sponge 支持基于自带模板和自定义模板两种方式生成你的项目所需的代码,下面是两种生成代码的框架图。
1. sponge 基于自带模板生成代码框架如下图所示,支持 sql 和 protobuf 两种方式。
<p align="center">
<img width="1500px" src="https://raw.githubusercontent.com/go-dev-frame/sponge/main/assets/sponge-framework.png">
</p>
<br>
2. sponge 基于自定义模板生成代码框架如下图所示,支持 json、sql、protobuf 三种方式。
<p align="center">
<img width="1200px" src="https://raw.githubusercontent.com/go-dev-frame/sponge/main/assets/template-framework.png">
</p>
<br>
### 微服务框架
sponge 创建的 6 种类型的后端服务中有 5 种属于微服务架构。下图展示了典型的微服务分层结构,具备高性能、高扩展性,并内置常用的服务治理功能。
<p align="center">
<img width="1000px" src="https://raw.githubusercontent.com/go-dev-frame/sponge/main/assets/microservices-framework.png">
</p>
<br>
创建的http和grpc服务代码的性能测试 50个并发总共100万个请求。
![http-server](https://raw.githubusercontent.com/zhufuyi/microservices_framework_benchmark/main/test/assets/http-server.png)
![grpc-server](https://raw.githubusercontent.com/zhufuyi/microservices_framework_benchmark/main/test/assets/grpc-server.png)
点击查看[**测试代码**](https://github.com/zhufuyi/microservices_framework_benchmark)。
<br>
### 目录结构
生成的服务代码目录结构遵循 [project-layout](https://github.com/golang-standards/project-layout)。
sponge 创建的服务代码目录结构遵循 [project-layout](https://github.com/golang-standards/project-layout)。
这是生成的`单体应用单体仓库(monolith)``微服务多仓库(multi-repo)`代码目录结构
sponge 支持创建 `单体应用单体仓库(monolith)``微服务多仓库(multi-repo)`、`微服务单体仓库(mono-repo)`三种类型的项目代码结构
1. 创建`单体应用单体仓库(monolith)`或`微服务多仓库(multi-repo)`代码目录结构如下:
```bash
.
@@ -176,7 +181,7 @@ sponge包含丰富的组件(按需使用)
<br>
这是生成的`微服务单体仓库(mono-repo)`代码目录结构(也就是大仓库代码目录结构)
2. 创建`微服务单体仓库(mono-repo)`代码目录结构(大仓库代码目录结构)如下
```bash
.

1
examples/README.md Normal file
View File

@@ -0,0 +1 @@
Rich examples of sponge usage view repository [**https://github.com/go-dev-frame/sponge_examples**](https://github.com/go-dev-frame/sponge_examples)

View File

@@ -28,7 +28,7 @@ func main() {
}
defer redisCli.Close()
locker, err := NewRedisLock(redisCli, "test_lock")
locker, err := dlock.NewRedisLock(redisCli, "test_lock")
if err != nil {
panic(err)
}