[Fix] Fix the issue that genRouterCode incorrect logic results in @Import annotations getting overwritten

This commit is contained in:
Yang, Gao 2019-03-24 14:41:28 +08:00
parent bc8fffe347
commit 3b00cfccec
1 changed files with 7 additions and 3 deletions

View File

@ -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 + `"],