Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加自动话路由容错 #557

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion generate/swaggergen/g_docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down