refactor and rename folder to group (#106)
* 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 () * support return () * revert * format api * refactor and rename folder to group Co-authored-by: kingxt <dream4kingxt@163.com>
This commit is contained in:
@@ -88,15 +88,17 @@ func (p *serviceEntityParser) parseLine(line string, api *spec.ApiSpec, annos []
|
||||
}
|
||||
}
|
||||
|
||||
if len(fields) < 3 {
|
||||
if len(fields) < 2 {
|
||||
return defaultErr
|
||||
}
|
||||
|
||||
method := fields[0]
|
||||
path := fields[1]
|
||||
req := fields[2]
|
||||
var req string
|
||||
var resp string
|
||||
|
||||
if len(fields) > 2 {
|
||||
req = fields[2]
|
||||
}
|
||||
if stringx.Contains(fields, returnsTag) {
|
||||
if fields[len(fields)-1] != returnsTag {
|
||||
resp = fields[len(fields)-1]
|
||||
|
||||
@@ -90,21 +90,20 @@ func MatchStruct(api string) (*ApiStruct, error) {
|
||||
continue
|
||||
}
|
||||
|
||||
if strings.HasPrefix(line, "import") {
|
||||
if isImportBeginLine(line) {
|
||||
parseImport = true
|
||||
}
|
||||
if parseImport && (strings.HasPrefix(line, "type") || strings.HasPrefix(line, "@server") ||
|
||||
strings.HasPrefix(line, "service")) {
|
||||
if parseImport && (isTypeBeginLine(line) || isServiceBeginLine(line)) {
|
||||
parseImport = false
|
||||
result.Imports = segment
|
||||
segment = line + "\n"
|
||||
continue
|
||||
}
|
||||
|
||||
if strings.HasPrefix(line, "type") {
|
||||
if isTypeBeginLine(line) {
|
||||
parseType = true
|
||||
}
|
||||
if strings.HasPrefix(line, "@server") || strings.HasPrefix(line, "service") {
|
||||
if isServiceBeginLine(line) {
|
||||
if parseType {
|
||||
parseType = false
|
||||
result.StructBody = segment
|
||||
@@ -122,3 +121,15 @@ func MatchStruct(api string) (*ApiStruct, error) {
|
||||
result.Service = segment
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func isImportBeginLine(line string) bool {
|
||||
return strings.HasPrefix(line, "import") && strings.HasSuffix(line, ".api")
|
||||
}
|
||||
|
||||
func isTypeBeginLine(line string) bool {
|
||||
return strings.HasPrefix(line, "type")
|
||||
}
|
||||
|
||||
func isServiceBeginLine(line string) bool {
|
||||
return strings.HasPrefix(line, "@server(") || (strings.HasPrefix(line, "service") && strings.HasSuffix(line, "{"))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user