update README

This commit is contained in:
zhuyasen 2024-03-15 00:52:35 +08:00
parent a68584fead
commit b60eb18ce9
5 changed files with 81 additions and 217 deletions

View File

@ -69,9 +69,11 @@ docs: mod fmt
# delete the templates code end
.PHONY: proto
# generate *.go and template code by proto files, if you do not refer to the proto file, the default is all the proto files in the api directory. you can specify the proto file, multiple files are separated by commas, e.g. make proto FILES=api/user/v1/user.proto. only for ⓶ Microservices created based on sql, ⓷ Web services created based on protobuf, ⓸ Microservices created based on protobuf, ⓹ grpc gateway service created based on protobuf
proto: mod fmt
# generate *.go and template code by proto files, if you do not refer to the proto file, the default is all the proto files in the api directory. you can specify the proto file, multiple files are separated by commas, e.g. make proto FILES=api/user/v1/user.proto, only for ⓶ Microservices created based on sql, ⓷ Web services created based on protobuf, ⓸ Microservices created based on protobuf, ⓹ grpc gateway service created based on protobuf
proto:
@bash scripts/protoc.sh $(FILES)
go mod tidy
@gofmt -s -w .
.PHONY: proto-doc

View File

@ -74,7 +74,7 @@ Sponge is essentially a microservice framework that includes code generation cap
- Configuration parsing [viper](https://github.com/spf13/viper)
- Configuration center [nacos](https://github.com/alibaba/nacos)
- Logging component [zap](https://github.com/uber-go/zap)
- Database ORM component [gorm](https://github.com/go-gorm/gorm)
- 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)
- 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)
@ -106,7 +106,7 @@ The project code directory structure created by sponge follows the [project-layo
│ ├── initial # Program initialization, consisting of three files: initApp initializes configurations, registerServers registers services (HTTP or grpc), and registerClose registers resource cleanup.
│ └── main.go # Program entry file
├── configs # Directory for configuration files
├── deployments # Directory for deployment scripts, supporting binary, Docker and Kubernetes deployments.
├── deployments # Directory for deployment scripts, supporting Bare Metal, Docker and Kubernetes deployments.
├─ docs # Directory for API interface Swagger documentation.
├── internal # Directory for code of private applications and libraries.
│ ├── cache # Cache directory wrapped around business logic.

View File

@ -1,30 +1,40 @@
### 安装依赖
> 安装sponge之前需要先安装`go`和`protoc`两个依赖。
要求使用go 1.16以上版本: [https://studygolang.com/dl](https://studygolang.com/dl)
**✅ 安装 go**
下载go地址 [https://studygolang.com/dl](https://studygolang.com/dl)
> 建议是1.20以上版本。
查看go版本 `go version`
> 注如果不能科学上网获取github的库可能会遇到超时失败问题建议设置为国内代理执行命令 **go env -w GOPROXY=https://goproxy.cn,direct**
<br>
**✅ 安装 protoc**
下载protoc地址 [https://github.com/protocolbuffers/protobuf/releases/tag/v25.2](https://github.com/protocolbuffers/protobuf/releases/tag/v25.2)
> 根据系统类型下载对应的 protoc 二进制文件,把 protoc 二进制文件移动到go二进制文件所在的目录。
查看protoc版本: `protoc --version`
---
<br>
安装完go和protoc之后接下来安装sponge支持在windows、mac、linux环境安装。
### Windows环境
> 如果不能科学上网安装sponge时获取github的库可能会遇到超时失败问题建议设置为国内代理执行命令 **go env -w GOPROXY=https://goproxy.cn,direct**
> 因为sponge依赖一些linux命令因此在windows环境中需要安装git bash、make来支持linux命令环境。
为了安装方便已经把sponge及其依赖的程序打包在一起下载地址(选择一个下载即可)
- 百度云: [**sponge-install.zip**](https://pan.baidu.com/s/1fiTiMROkiIIzAdj2bk93CA?pwd=prys)。
- 蓝奏云:[**sponge安装文件**](https://wwm.lanzoue.com/b049fldpi) 密码:5rq9共下载4个文件安装前先看`安装说明.txt`文件。
下载文件后:
(1) 解压文件,双击 **install.bat** 进行安装安装git过程一直默认即可(如果已经安装过git可以跳过安装git这个步骤)。
(2) 在任意文件夹下右键(显示更多选项)选择【Open Git Bash here】打开git bash终端
```bash
# 初始化sponge自动安装sponge依赖插件
sponge init
# 查看sponge版本
sponge -v
```
> 注: 使用sponge开发时请使用git bash终端不要使用系统默认的cmd否则会出现找不到命令的错误。
在windows除了上面安装sponge方式还提供了原生安装点击查看【🏷安装 sponge】 --> 【windows环境】[安装文档](https://go-sponge.com/zh-cn/quick-start?id=%f0%9f%8f%b7%e5%ae%89%e8%a3%85-sponge)。
<br>
@ -34,7 +44,7 @@
### Linux或MacOS环境
(1) 把`$GOBIN`添加到系统path如果已经设置过可以跳过此步骤。
(1) 把`GOBIN`添加到系统环境变量**path**,如果已经设置过可以跳过此步骤。
```bash
# 打开 .bashrc 文件
@ -43,8 +53,8 @@ vim ~/.bashrc
# 复制下面命令到.bashrc
export GOROOT="/opt/go" # 你的go安装目录
export GOPATH=$HOME/go # 设置 go get 命令下载第三方包的目录
export GOBIN=$GOPATH/bin # 设置 go install 命令编译后生成可执行二进制文件的存放目录
export PATH=$PATH:$GOBIN:$GOROOT/bin # 把$GOBIN目录添加到系统path
export GOBIN=$GOPATH/bin # 设置 go install 命令编译后生成可执行文件的存放目录
export PATH=$PATH:$GOBIN:$GOROOT/bin # 把GOBIN目录添加到系统环境变量path
# 保存 .bashrc 文件后,使设置生效
source ~/.bashrc
@ -55,93 +65,13 @@ go env GOBIN
<br>
(2) 执行命令安装spongesponge和依赖插件将安装到 `$GOBIN` 目录下
(2) 把sponge及其依赖的插件安装到 `GOBIN` 目录
```bash
# 安装sponge
go install github.com/zhufuyi/sponge/cmd/sponge@latest
**✅ 安装 protoc**
# 初始化sponge自动安装sponge依赖插件
sponge init
下载protoc地址 [https://github.com/protocolbuffers/protobuf/releases/tag/v25.2](https://github.com/protocolbuffers/protobuf/releases/tag/v25.2)
# 查看插件是否都安装成功,如果发现有插件没有安装成功,执行命令重试 sponge plugins --install
sponge plugins
# 查看sponge版本
sponge -v
```
<br>
---
<br>
### Windows环境
> 在windows环境中需要安装mingw64、make、cmder来支持linux命令环境才可以使用sponge。
**✅ 安装 mingw64**
下载mingw64地址 [x86_64-8.1.0-release-posix-seh-rt_v6-rev0.7z](https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/8.1.0/threads-posix/seh/x86_64-8.1.0-release-posix-seh-rt_v6-rev0.7z)
下载后解压到`D:\Program Files\mingw64`目录把linux常用命令所在的目录`D:\Program Files\mingw64\bin`添加系统环境变量PATH。
<br>
**✅ 安装 make 命令**
切换到`D:\Program Files\mingw64\bin`目录,找到`mingw32-make.exe`可执行文件,复制并改名为`make.exe`。
查看make版本`make -v`
<br>
**✅ 安装 cmder**
下载cmder地址 [cmder-v1.3.20.zip](https://github.com/cmderdev/cmder/releases/download/v1.3.20/cmder.zip)
下载后解压到`D:\Program Files\cmder`目录下,并把目录`D:\Program Files\cmder`添加到系统环境变量path。
对cmder进行简单的配置
- **解决输入命令时的空格问题**打开cmder界面按下组合键win+alt+p进入设置界面在左上角搜索`Monospace`,取消勾选,保存退出。
- **配置右键启动cmder**,按下组合键`win+x`,再按字母`a`进入有管理权限的终端,执行命令`Cmder.exe /REGISTER ALL`。 随便在一个文件夹里按下鼠标右键,选择`Cmder Here`即可打开cmder界面。
> ⚠ 在windows环境使用sponge开发项目为了避免找不到linux命令错误请使用cmder不要用系统自带的cmd终端、Goland和VS Code下的终端。
打开`cmder.exe`终端检查是否支持常用的linux命令。
```bash
ls --version
make --version
cp --version
chmod --version
rm --version
sed --version
```
<br>
**✅ 安装和运行 sponge**
打开`cmder.exe`终端(不是windows自带的cmd)。
(1) 把`GOBIN`添加到系统path如果已经设置过可以跳过此步骤。
```bash
# 设置 go get 命令下载第三方包的目录
setx GOPATH "D:\你的目录"
# 设置 go install 命令编译后生成可执行二进制文件的存放目录
setx GOBIN "D:\你的目录\bin"
# 关闭终端然后开启一个新的终端查看GOBIN目录
go env GOBIN
```
<br>
(2) 执行命令安装spongesponge和依赖插件将安装到`GOBIN`目录下。
根据系统类型下载对应的 **protoc** 可执行文件,把 **protoc** 可执行文件移动到`GOBIN`目录下。
```bash
# 安装sponge
@ -165,7 +95,7 @@ sponge -v
### Docker环境
> ⚠ 使用docker启动的sponge UI服务只支持在界面操作来生成代码功能如果需要在生成的服务代码基础上进行开发还是需要根据上面的安装说明在本地安装sponge和依赖插件的二进制文件
> ⚠ 使用docker启动的sponge UI服务只支持在界面操作来生成代码功能如果需要在生成的服务代码基础上进行开发还是需要根据上面的安装说明在本地安装sponge和依赖插件。
**方式一Docker启动**

View File

@ -1,28 +1,37 @@
### Installing Dependencies
> Before installing Sponge, you need to install two dependencies: `go` and `protoc`.
**✅ Installing go**
Download go from: [https://go.dev/doc/install](https://go.dev/doc/install)
> Recommended version: 1.20 or above.
Check go version: `go version`
Requirements Go 1.16 and above, [https://go.dev/doc/install](https://go.dev/doc/install)
<br>
**✅ Installing protoc**
Download protoc from: [https://github.com/protocolbuffers/protobuf/releases/tag/v25.2](https://github.com/protocolbuffers/protobuf/releases/tag/v25.2)
> Download the protoc binaries according to the system type, move the protoc binaries to the directory where the go binaries are located.
Check protoc version: `protoc --version`
---
<br>
After installing go and protoc, proceed to install Sponge. Sponge can be installed on Windows, macOS, and Linux environments.
### Windows Environment
> Because sponge depends on some linux commands, git bash and make need to be installed in windows to support the linux command environment.
<br>
For installation convenience, sponge and its dependent programs have been packaged together, download address: [sponge-install.zip](https://drive.google.com/drive/folders/1T55lLXDBIQCnL5IQ-i1hWJovgLI2l0k1?usp=sharing)
After downloading the file:
1. Unzip the file, double-click **install.bat** to install, the installation process of git is always the default (if you have installed git, you can skip this step)
2. Right-click any folder (Show more options) and select **Open Git Bash here** to open the git bash terminal:
```bash
# Initialize sponge, automatically install sponge's dependency plugins
sponge init
# Check sponge version
sponge -v
```
> Note: When using sponge development, please use git bash terminal, do not use the system default cmd, otherwise there will be an error that cannot find the command.
In addition to the above installation of sponge in windows, it also provides native installation, click to view **Installing Sponge** --> **Windows Environment** [installation documentation](https://go-sponge.com/quick-start?id=%f0%9f%8f%b7installing-sponge).
<br>
@ -32,7 +41,7 @@ After installing go and protoc, proceed to install Sponge. Sponge can be install
### Linux or macOS Environment
1. Add `$GOBIN` to the system path, skip this step if already set.
1. Add `GOBIN` to the system environment variable path, skip this step if already set.
```bash
# Open .bashrc file
@ -42,7 +51,7 @@ vim ~/.bashrc
export GOROOT="/opt/go" # your go installation directory
export GOPATH=$HOME/go # Set the directory where the "go get" command downloads third-party packages
export GOBIN=$GOPATH/bin # Set the directory where the executable binaries are compiled by the "go install" command.
export PATH=$PATH:$GOBIN:$GOROOT/bin # Add the $GOBIN directory to the system path.
export PATH=$PATH:$GOBIN:$GOROOT/bin # Add the GOBIN directory to the system environment variable path.
# Save .bashrc file, and make the settings take effect
source ~/.bashrc
@ -53,93 +62,13 @@ go env GOBIN
<br>
2. Execute the command to install sponge, sponge and dependent plugins will be installed to the `$GOBIN` directory.
2. Install sponge and its dependent plugins into the `GOBIN` directory.
```bash
# Install Sponge
go install github.com/zhufuyi/sponge/cmd/sponge@latest
**✅ Install protoc**
# Initialize Sponge, automatically install Sponge's dependency plugins
sponge init
Download protoc from: [https://github.com/protocolbuffers/protobuf/releases/tag/v25.2](https://github.com/protocolbuffers/protobuf/releases/tag/v25.2)
# Check if all plugins have been successfully installed. If any plugins fail to install, retry with the command: sponge plugins --install
sponge plugins
# Check Sponge version
sponge -v
```
<br>
---
<br>
### Windows Environment
> In the Windows environment, you need to install mingw64, make, and cmder to support the Linux command environment required by Sponge.
**✅ Installing mingw64**
Download mingw64 from: [x86_64-8.1.0-release-posix-seh-rt_v6-rev0.7z](https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/8.1.0/threads-posix/seh/x86_64-8.1.0-release-posix-seh-rt_v6-rev0.7z)
After downloading, extract it to the directory `D:\Program Files\mingw64`, and add the directory containing frequently used Linux commands, such as `D:\Program Files\mingw64\bin`, to the system environment variable "PATH".
<br>
**✅ Installing the make command**
Navigate to the directory `D:\Program Files\mingw64\bin`, find the executable file `mingw32-make.exe`, and copy and rename it to `make.exe`.
Check make version: `make -v`
<br>
**✅ Installing cmder**
Download cmder from: [cmder-v1.3.20.zip](https://github.com/cmderdev/cmder/releases/download/v1.3.20/cmder.zip)
After downloading, extract it to the directory `D:\Program Files\cmder`, and add the directory `D:\Program Files\cmder` to the system environment variable "PATH".
Perform basic configuration for cmder:
- **Resolve Space Issue While Typing Commands**: Open the cmder interface, press `win+alt+p` to access the settings, search for `Monospace` in the upper left corner, uncheck it, and save and exit.
- **Configure Right-Click Launch for cmder**: Press the `win+x` key combination, then press the letter `a` to enter the administrative terminal. Execute the command `Cmder.exe /REGISTER ALL`. Right-click in any folder and choose `Cmder Here` to open the cmder interface.
> ⚠ When developing projects with Sponge in a Windows environment, to avoid issues with missing Linux commands, please use cmder instead of the built-in cmd terminal, the terminal in Goland, or the terminal in VS Code.
Open the `cmder.exe` terminal and check if common Linux commands are supported.
```bash
ls --version
make --version
cp --version
chmod --version
rm --version
sed --version
```
<br>
**✅ Installing Sponge**
Open the `cmder.exe` terminal (not the built-in Windows cmd).
1. Add `GOBIN` to the system path, skip this step if already set.
```bash
# Set the directory where the "go get" command downloads third-party packages
setx GOPATH "D:\your-directory"
# Set the directory where the executable binary files generated by the "go install" command are stored.
setx GOBIN "D:\your-directory\bin"
# Close the terminal and open a new one to view the GOBIN directory.
go env GOBIN
```
<br>
2. Execute the command to install sponge, sponge and dependent plugins will be installed to the `GOBIN` directory.
Download the corresponding **protoc** executable file according to the system type, and move the **protoc** executable file to the same directory as the **go** executable file.
```bash
# Install Sponge

View File

@ -1,11 +1,14 @@
## [English](../README.md) | 简体中文
[sponge](https://github.com/zhufuyi/sponge) 是一个集成了 `自动生成代码`、`Gin和GRPC` 的基础开发框架。sponge拥有丰富的生成代码命令生成不同的功能代码可以组合成完整的服务(类似人为打散的海绵细胞可以自动重组成一个新的海绵)。代码解耦模块化设计很容易构建出从开发到部署的完整工程项目只需在生成的模板代码上填充业务逻辑代码极大的提高了开发效率和降低了开发难度使用go也可以"低代码开发"。
<br>
[sponge](https://github.com/zhufuyi/sponge) 是一个集成了 `自动生成代码`、`Gin和GRPC` 的基础开发框架。sponge拥有丰富的生成代码命令生成不同的功能代码可以组合成完整的服务(类似人为打散的海绵细胞可以自动重组成一个新的海绵)。代码解耦模块化设计很容易构建出从开发到部署的完整工程项目只需在生成的模板代码上填充业务逻辑代码大幅提高了开发效率和降低了开发难度使用go也可以"低代码开发"。
<br>
如果开发只有简单CRUD api接口的web或微服务不需要编写任何go代码就可以编译并部署到linux服务器、docker、k8s上只需要连接到数据库(mysql、mongodb、postgresql、tidb、sqlite)就可以一键自动生成完整的服务代码。
如果开发通用的web或微服务只需聚焦`在数据库定义表`、`在proto文件定义api接口`、`在生成的模板文件填写业务逻辑代码`三个核心部分其他go代码都由sponge自动生成。
如果开发通用的web或微服务只需聚焦`在数据库定义表`、`在proto文件定义api接口`、`在生成的模板文件填写业务逻辑代码`三个核心部分其他go代码都由sponge自动生成。
<br>
@ -60,7 +63,7 @@ sponge包含丰富的组件(按需使用)
- 配置解析 [viper](https://github.com/spf13/viper)
- 配置中心 [nacos](https://github.com/alibaba/nacos)
- 日志 [zap](https://github.com/uber-go/zap)
- 数据库组件 [gorm](https://github.com/go-gorm/gorm)
- 数据库组件 [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)