From a56257aaaff473d76a7ccfb94241150119a2e13d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=80=99=E8=83=9C=E6=96=8C?= Date: Fri, 26 Oct 2018 17:44:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=87=AA=E5=8A=A8=E8=AF=9D?= =?UTF-8?q?=E8=B7=AF=E7=94=B1=E5=AE=B9=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- generate/swaggergen/g_docs.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/generate/swaggergen/g_docs.go b/generate/swaggergen/g_docs.go index 351a289bc..fd752556e 100644 --- a/generate/swaggergen/g_docs.go +++ b/generate/swaggergen/g_docs.go @@ -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" ) @@ -519,6 +519,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 { @@ -535,6 +546,7 @@ func parserComments(f *ast.FuncDecl, controllerName, pkgpath string) error { for _, c := range comments.List { t := strings.TrimSpace(strings.TrimLeft(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 {