add anonymous annotation (#134)

* rebase upstream

* rebase

* trim no need line

* trim no need line

* trim no need line

* update doc

* remove update

* remove no need

* remove no need

* goctl add jwt support

* goctl add jwt support

* goctl add jwt support

* goctl support import

* goctl support import

* support return ()

* revert

* refactor and rename folder to group

* remove no need

* add anonymous annotation

* optimized

* rename

* rename

* update test

* optimized new command

Co-authored-by: kingxt <dream4kingxt@163.com>
This commit is contained in:
kingxt
2020-10-16 19:35:18 +08:00
committed by GitHub
parent 7e83895c6e
commit 1d9c4a4c4b
8 changed files with 79 additions and 13 deletions

View File

@@ -11,10 +11,11 @@ import (
var emptyType spec.Type
type ApiStruct struct {
Info string
StructBody string
Service string
Imports string
Info string
StructBody string
Service string
Imports string
serviceBeginLine int
}
func GetType(api *spec.ApiSpec, t string) spec.Type {
@@ -69,7 +70,7 @@ func unread(r *bufio.Reader) error {
return r.UnreadRune()
}
func MatchStruct(api string) (*ApiStruct, error) {
func ParseApi(api string) (*ApiStruct, error) {
var result ApiStruct
scanner := bufio.NewScanner(strings.NewReader(api))
var parseInfo = false
@@ -104,13 +105,13 @@ func MatchStruct(api string) (*ApiStruct, error) {
parseType = true
}
if isServiceBeginLine(line) {
parseService = true
if parseType {
parseType = false
result.StructBody = segment
segment = line + "\n"
continue
}
parseService = true
}
segment += scanner.Text() + "\n"
}
@@ -119,6 +120,7 @@ func MatchStruct(api string) (*ApiStruct, error) {
return nil, errors.New("no service defined")
}
result.Service = segment
result.serviceBeginLine = lineBeginOfService(api)
return &result, nil
}
@@ -133,3 +135,16 @@ func isTypeBeginLine(line string) bool {
func isServiceBeginLine(line string) bool {
return strings.HasPrefix(line, "@server(") || (strings.HasPrefix(line, "service") && strings.HasSuffix(line, "{"))
}
func lineBeginOfService(api string) int {
scanner := bufio.NewScanner(strings.NewReader(api))
var number = 0
for scanner.Scan() {
line := strings.TrimSpace(scanner.Text())
if isServiceBeginLine(line) {
break
}
number++
}
return number
}