This commit is contained in:
道一 2020-07-31 12:53:10 +08:00 committed by GitHub
commit a3eaf9375f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 1 deletions

View File

@ -36,7 +36,7 @@ import (
"github.com/astaxie/beego/swagger"
"github.com/astaxie/beego/utils"
beeLogger "github.com/beego/bee/logger"
"github.com/beego/bee/logger"
bu "github.com/beego/bee/utils"
)
@ -533,6 +533,17 @@ func peekNextSplitString(ss string) (s string, spacePos int) {
}
return
}
/**
Comment format with a single space as the semantic segmentation,
single comma for the array information division
*/
func formatComment(comment string) string {
spaceReg, _ := regexp.Compile("[ \t]+")
commaReg, _ := regexp.Compile(",[ \t]+")
comment = spaceReg.ReplaceAllString(comment, " ")
comment = commaReg.ReplaceAllString(comment, ",")
return comment
}
// parse the func comments
func parserComments(f *ast.FuncDecl, controllerName, pkgpath string) error {
@ -549,6 +560,7 @@ func parserComments(f *ast.FuncDecl, controllerName, pkgpath string) error {
for _, c := range comments.List {
t := strings.TrimSpace(strings.TrimPrefix(c.Text, "//"))
if strings.HasPrefix(t, "@router") {
t = formatComment(t)
elements := strings.TrimSpace(t[len("@router"):])
e1 := strings.SplitN(elements, " ", 2)
if len(e1) < 1 {