From 9418b243d07c4f54bb92688e43973ab15e42e23a Mon Sep 17 00:00:00 2001 From: Ming Deng Date: Tue, 22 Dec 2020 21:19:13 +0800 Subject: [PATCH 1/2] Fix generated code 4384 --- parser.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parser.go b/parser.go index 3a311894..5e6b9111 100644 --- a/parser.go +++ b/parser.go @@ -500,7 +500,7 @@ func genRouterCode(pkgRealpath string) { beego.GlobalControllerRouter["` + k + `"] = append(beego.GlobalControllerRouter["` + k + `"], beego.ControllerComments{ Method: "` + strings.TrimSpace(c.Method) + `", - ` + `Router: "` + c.Router + `"` + `, + ` + "Router: `" + c.Router + "`" + `, AllowHTTPMethods: ` + allmethod + `, MethodParams: ` + methodParams + `, Filters: ` + filters + `, From db6af39bcd216e44053a600d32f4e86ea2fb807c Mon Sep 17 00:00:00 2001 From: Ming Deng Date: Tue, 22 Dec 2020 21:29:23 +0800 Subject: [PATCH 2/2] Using commentRouter.go as generated file name --- parser.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/parser.go b/parser.go index 5e6b9111..9137a749 100644 --- a/parser.go +++ b/parser.go @@ -49,7 +49,6 @@ func init() { var ( lastupdateFilename = "lastupdate.tmp" - commentFilename string pkgLastupdate map[string]int64 genInfoList map[string][]ControllerComments @@ -70,16 +69,13 @@ var ( } ) -const commentPrefix = "commentsRouter_" +const commentFilename = "commentsRouter.go" func init() { pkgLastupdate = make(map[string]int64) } func parserPkg(pkgRealpath, pkgpath string) error { - rep := strings.NewReplacer("\\", "_", "/", "_", ".", "_") - commentFilename, _ = filepath.Rel(AppPath, pkgRealpath) - commentFilename = commentPrefix + rep.Replace(commentFilename) + ".go" if !compareFile(pkgRealpath) { logs.Info(pkgRealpath + " no changed") return nil @@ -102,7 +98,10 @@ func parserPkg(pkgRealpath, pkgpath string) error { if specDecl.Recv != nil { exp, ok := specDecl.Recv.List[0].Type.(*ast.StarExpr) // Check that the type is correct first beforing throwing to parser if ok { - parserComments(specDecl, fmt.Sprint(exp.X), pkgpath) + err = parserComments(specDecl, fmt.Sprint(exp.X), pkgpath) + if err != nil { + return err + } } } }