1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-23 20:50:55 +00:00

Merge pull request #2 from flycash/develop-1

Fix generated code 4384
This commit is contained in:
Ming Deng 2020-12-26 21:32:13 +08:00 committed by GitHub
commit 89d4c9a3df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -49,7 +49,6 @@ func init() {
var ( var (
lastupdateFilename = "lastupdate.tmp" lastupdateFilename = "lastupdate.tmp"
commentFilename string
pkgLastupdate map[string]int64 pkgLastupdate map[string]int64
genInfoList map[string][]ControllerComments genInfoList map[string][]ControllerComments
@ -70,16 +69,13 @@ var (
} }
) )
const commentPrefix = "commentsRouter_" const commentFilename = "commentsRouter.go"
func init() { func init() {
pkgLastupdate = make(map[string]int64) pkgLastupdate = make(map[string]int64)
} }
func parserPkg(pkgRealpath, pkgpath string) error { func parserPkg(pkgRealpath, pkgpath string) error {
rep := strings.NewReplacer("\\", "_", "/", "_", ".", "_")
commentFilename, _ = filepath.Rel(AppPath, pkgRealpath)
commentFilename = commentPrefix + rep.Replace(commentFilename) + ".go"
if !compareFile(pkgRealpath) { if !compareFile(pkgRealpath) {
logs.Info(pkgRealpath + " no changed") logs.Info(pkgRealpath + " no changed")
return nil return nil
@ -102,7 +98,10 @@ func parserPkg(pkgRealpath, pkgpath string) error {
if specDecl.Recv != nil { if specDecl.Recv != nil {
exp, ok := specDecl.Recv.List[0].Type.(*ast.StarExpr) // Check that the type is correct first beforing throwing to parser exp, ok := specDecl.Recv.List[0].Type.(*ast.StarExpr) // Check that the type is correct first beforing throwing to parser
if ok { if ok {
parserComments(specDecl, fmt.Sprint(exp.X), pkgpath) err = parserComments(specDecl, fmt.Sprint(exp.X), pkgpath)
if err != nil {
return err
}
} }
} }
} }
@ -500,7 +499,7 @@ func genRouterCode(pkgRealpath string) {
beego.GlobalControllerRouter["` + k + `"] = append(beego.GlobalControllerRouter["` + k + `"], beego.GlobalControllerRouter["` + k + `"] = append(beego.GlobalControllerRouter["` + k + `"],
beego.ControllerComments{ beego.ControllerComments{
Method: "` + strings.TrimSpace(c.Method) + `", Method: "` + strings.TrimSpace(c.Method) + `",
` + `Router: "` + c.Router + `"` + `, ` + "Router: `" + c.Router + "`" + `,
AllowHTTPMethods: ` + allmethod + `, AllowHTTPMethods: ` + allmethod + `,
MethodParams: ` + methodParams + `, MethodParams: ` + methodParams + `,
Filters: ` + filters + `, Filters: ` + filters + `,