From 3b00cfccec18dac833c3afddcf1fc7839fc59fd1 Mon Sep 17 00:00:00 2001 From: "Yang, Gao" Date: Sun, 24 Mar 2019 14:41:28 +0800 Subject: [PATCH] [Fix] Fix the issue that genRouterCode incorrect logic results in @Import annotations getting overwritten --- parser.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/parser.go b/parser.go index a8690274..81990a4a 100644 --- a/parser.go +++ b/parser.go @@ -459,13 +459,17 @@ func genRouterCode(pkgRealpath string) { imports := "" if len(c.ImportComments) > 0 { for _, i := range c.ImportComments { + var s string if i.ImportAlias != "" { - imports += fmt.Sprintf(` + s = fmt.Sprintf(` %s "%s"`, i.ImportAlias, i.ImportPath) } else { - imports += fmt.Sprintf(` + s = fmt.Sprintf(` "%s"`, i.ImportPath) } + if !strings.Contains(globalimport, s) { + imports += s + } } } @@ -490,7 +494,7 @@ func genRouterCode(pkgRealpath string) { }`, filters) } - globalimport = imports + globalimport += imports globalinfo = globalinfo + ` beego.GlobalControllerRouter["` + k + `"] = append(beego.GlobalControllerRouter["` + k + `"],