goctl model reactor (#15)

* reactor sql generation

* reactor sql generation

* add console & example

* optimize unit test & add document

* modify default config

* remove test file

* Revert "remove test file"

This reverts commit 81041f9e

* fix stringx.go & optimize example

* remove unused code
This commit is contained in:
Keson
2020-08-19 10:41:19 +08:00
committed by GitHub
parent 1252bd9cde
commit d21d770b5b
64 changed files with 1505 additions and 2306 deletions

View File

@@ -3,9 +3,7 @@
## goctl用途
* 定义api请求
* 根据定义的api自动生成golang(后端), java(iOS & Android), typescript(web & 晓程序)dart(flutter)
* 生成MySQL CURD (https://goctl.xiaoheiban.cn)
* 生成MongoDB CURD (https://goctl.xiaoheiban.cn)
* 生成MySQL CURD 详情见[goctl model模块](https://github.com/tal-tech/go-zero/tools/goctl/model)
## goctl使用说明
#### goctl参数说明
@@ -188,79 +186,5 @@ service user-api {
#### 根据定义好的api文件生成Dart代码
`goctl api dart -api user/user.api -dir ./src`
## 根据定义好的简单go文件生成mongo代码文件(仅限golang使用)
`goctl model mongo -src {{yourDir}}/xiao/service/xhb/user/model/usermodel.go -cache yes`
-src需要提供简单的usermodel.go文件里面只需要提供一个结构体即可
-cache 控制是否需要缓存 yes=需要 no=不需要
src 示例代码如下
```
package model
type User struct {
Name string `o:"find,get,set" c:"姓名"`
Age int `o:"find,get,set" c:"年纪"`
School string `c:"学校"`
}
```
结构体中不需要提供Id,CreateTime,UpdateTime三个字段会自动生成
结构体中每个tag有两个可选标签 c 和 o
c是改字段的注释
o是改字段需要生产的操作函数 可以取得get,find,set 分别表示生成返回单个对象的查询方法,返回多个对象的查询方法,设置该字段方法
生成的目标文件会覆盖该简单go文件
## goctl rpc生成
命令 `goctl rpc proto -proto ${proto} -service ${serviceName} -project ${projectName} -dir ${directory} -shared ${shared}`
如: `goctl rpc proto -proto test.proto -service test -project xjy -dir .`
参数说明:
- ${proto}: proto文件
- ${serviceName}: rpc服务名称
- ${projectName}: 所属项目如xjy,xhb,crm,hera具体查看help主要为了根据不同项目服务往redis注册key可选
- ${directory}: 输出目录
- ${shared}: shared文件生成目录可选默认为${pwd}/shared
生成目录结构示例:
``` go
.
├── shared [示例目录,可自己指定,强制覆盖更新]
│   └── contentservicemodel.go
├── test
│   ├── etc
│   │   └── test.json
│   ├── internal
│   │   ├── config
│   │   │   └── config.go
│   │   ├── handler [强制覆盖更新]
│   │   │   ├── changeavatarhandler.go
│   │   │   ├── changebirthdayhandler.go
│   │   │   ├── changenamehandler.go
│   │   │   ├── changepasswordhandler.go
│   │   │   ├── changeuserinfohandler.go
│   │   │   ├── getuserinfohandler.go
│   │   │   ├── loginhandler.go
│   │   │   ├── logouthandler.go
│   │   │   └── testhandler.go
│   │   ├── logic
│   │   │   ├── changeavatarlogic.go
│   │   │   ├── changebirthdaylogic.go
│   │   │   ├── changenamelogic.go
│   │   │   ├── changepasswordlogic.go
│   │   │   ├── changeuserinfologic.go
│   │   │   ├── getuserinfologic.go
│   │   │   ├── loginlogic.go
│   │   │   └── logoutlogic.go
│   │   └── svc
│   │   └── servicecontext.go
│   ├── pb
│   │   └── test.pb.go
│   └── test.go [强制覆盖更新]
└── test.proto
```
- 注意 目前rpc目录生成的proto文件暂不支持import外部proto文件
* 如有不理解的地方随时问Kim/Kevin