Skip to content

Commit

Permalink
update quick start (zeromicro#63)
Browse files Browse the repository at this point in the history
* rebase upstream

* rebase

* trim no need line

* trim no need line

* trim no need line

* update doc

* update readme.md

Co-authored-by: kingxt <[email protected]>
  • Loading branch information
kingxt and kingxt authored Sep 11, 2020
1 parent 72aeac3 commit 754e631
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 54 deletions.
5 changes: 5 additions & 0 deletions doc/goctl.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
* 生成MongoDB CURD+Cache

## goctl使用说明

#### 快速生成服务
* api: goctl api new xxxx
* rpc: goctl rpc new xxxx

#### goctl参数说明

`goctl api [go/java/ts] [-api user/user.api] [-dir ./src]`
Expand Down
57 changes: 3 additions & 54 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,61 +107,10 @@ go get -u github.com/tal-tech/go-zero

确保goctl可执行

2. 定义API文件,比如greet.api,可以在vs code里安装`goctl`插件,支持api语法

```go
type Request struct {
Name string `path:"name,options=you|me"` // 框架自动验证请求参数是否合法
}

type Response struct {
Message string `json:"message"`
}
2. 快速生成api服务

service greet-api {
@server(
handler: GreetHandler
)
get /greet/from/:name(Request) returns (Response);
}
```

也可以通过goctl生成api模本文件,命令如下:

```shell
goctl api -o greet.api
```

3. 生成go服务端代码

```shell
goctl api go -api greet.api -dir greet
```

生成的文件结构如下:

```
├── greet
│   ├── etc
│   │   └── greet-api.yaml // 配置文件
│   ├── greet.go // main文件
│   └── internal
│   ├── config
│   │   └── config.go // 配置定义
│   ├── handler
│   │   ├── greethandler.go // get/put/post/delete等路由定义文件
│   │   └── routes.go // 路由列表
│   ├── logic
│   │   └── greetlogic.go // 请求逻辑处理文件
│   ├── svc
│   │   └── servicecontext.go // 请求上下文,可以传入mysql, redis等依赖
│   └── types
│   └── types.go // 请求、返回等类型定义
└── greet.api // api描述文件
```
生成的代码可以直接运行:

```shell
goctl api new greet
cd greet
go run greet.go -f etc/greet-api.yaml
```
Expand All @@ -185,7 +134,7 @@ Content-Length: 0
* 可以在servicecontext.go里面传递依赖给logic,比如mysql, redis等
* 在api定义的get/post/put/delete等请求对应的logic里增加业务处理逻辑

4. 可以根据api文件生成前端需要的Java, TypeScript, Dart, JavaScript代码
3. 可以根据api文件生成前端需要的Java, TypeScript, Dart, JavaScript代码

```shell
goctl api java -api greet.api -dir greet
Expand Down

0 comments on commit 754e631

Please sign in to comment.