Skip to content

Commit

Permalink
api support empty request or empty response (zeromicro#72)
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

* remove update

* api support empty request or empty response

* update readme

Co-authored-by: kingxt <[email protected]>
  • Loading branch information
kingxt and kingxt authored Sep 14, 2020
1 parent 9a57993 commit 598ff6d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
21 changes: 14 additions & 7 deletions tools/goctl/api/parser/servicestate.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io"
"strings"

"github.com/tal-tech/go-zero/core/stringx"
"github.com/tal-tech/go-zero/tools/goctl/api/spec"
)

Expand Down Expand Up @@ -57,13 +58,14 @@ type serviceEntityParser struct {
}

func (p *serviceEntityParser) parseLine(line string, api *spec.ApiSpec, annos []spec.Annotation) error {
line = strings.TrimSpace(line)
var defaultErr = fmt.Errorf("wrong line %q, %q", line, routeSyntax)

line = strings.TrimSpace(line)
var buffer = new(bytes.Buffer)
buffer.WriteString(line)
reader := bufio.NewReader(buffer)
var builder strings.Builder
var fields []string
var fields = make([]string, 0)
for {
ch, _, err := reader.ReadRune()
if err != nil {
Expand All @@ -87,17 +89,22 @@ func (p *serviceEntityParser) parseLine(line string, api *spec.ApiSpec, annos []
}

if len(fields) < 3 {
return fmt.Errorf("wrong line %q, %q", line, routeSyntax)
return defaultErr
}

method := fields[0]
path := fields[1]
req := fields[2]
var returns string
if len(fields) > 4 {
returns = fields[4]
if fields[3] != returnsTag {
return fmt.Errorf("wrong line %q, %q", line, routeSyntax)

if stringx.Contains(fields, returnsTag) {
if fields[len(fields)-1] != returnsTag {
returns = fields[len(fields)-1]
} else {
return defaultErr
}
if fields[2] == returnsTag {
req = ""
}
}

Expand Down
13 changes: 3 additions & 10 deletions tools/goctl/goctl.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,11 @@
> -api 自定义api所在路径
>
> -dir 自定义生成目录
#### 保持goctl总是最新版

第一次运行会在~/.goctl里增加下面两行:

```Plain Text
url = http://47.97.184.41:7777/
```
#### API 语法说明

```Plain Text
```golang

info(
title: doc title
desc: >
Expand Down Expand Up @@ -128,7 +121,7 @@ service user-api {

1. info部分:描述了api基本信息,比如Auth,api是哪个用途。
2. type部分:type类型声明和golang语法兼容。
3. service部分:service代表一组服务,一个服务可以由多组名称相同的service组成,可以针对每一组service配置jwt和auth认证,另外通过folder属性可以指定service生成所在子目录
3. service部分:service代表一组服务,一个服务可以由多组名称相同的service组成,可以针对每一组service配置folder属性来指定service生成所在子目录
service里面包含api路由,比如上面第一组service的第一个路由,doc用来描述此路由的用途,GetProfileHandler表示处理这个路由的handler,
`get /api/profile/:name(getRequest) returns(getResponse)` 中get代表api的请求方式(get/post/put/delete), `/api/profile/:name` 描述了路由path,`:name`通过
请求getRequest里面的属性赋值,getResponse为返回的结构体,这两个类型都定义在2描述的类型中。
Expand Down

0 comments on commit 598ff6d

Please sign in to comment.