From 807c3de8a7dcb2d84d4b25795aabdaddfb1909a0 Mon Sep 17 00:00:00 2001 From: astaxie Date: Wed, 6 Jan 2016 11:55:56 +0800 Subject: [PATCH] fix issue with new version --- apiapp.go | 18 +++++++++--------- bee.go | 1 + fix.go | 19 +++++++++++++++++++ g_appcode.go | 6 +++--- g_controllers.go | 6 +++--- g_docs.go | 2 +- 6 files changed, 36 insertions(+), 16 deletions(-) create mode 100644 fix.go diff --git a/apiapp.go b/apiapp.go index ec6bb95..8ae376e 100644 --- a/apiapp.go +++ b/apiapp.go @@ -76,9 +76,9 @@ import ( ) func main() { - if beego.RunMode == "dev" { - beego.DirectoryIndex = true - beego.StaticDir["/swagger"] = "swagger" + if beego.BConfig.RunMode == "dev" { + beego.BConfig.WebConfig.DirectoryIndex = true + beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger" } beego.Run() } @@ -100,9 +100,9 @@ func init() { } func main() { - if beego.RunMode == "dev" { - beego.DirectoryIndex = true - beego.StaticDir["/swagger"] = "swagger" + if beego.BConfig.RunMode == "dev" { + beego.BConfig.WebConfig.DirectoryIndex = true + beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger" } beego.Run() } @@ -319,7 +319,7 @@ func (o *ObjectController) Post() { // @Failure 403 :objectId is empty // @router /:objectId [get] func (o *ObjectController) Get() { - objectId := o.Ctx.Input.Params[":objectId"] + objectId := o.Ctx.Input.Param(":objectId") if objectId != "" { ob, err := models.GetOne(objectId) if err != nil { @@ -350,7 +350,7 @@ func (o *ObjectController) GetAll() { // @Failure 403 :objectId is empty // @router /:objectId [put] func (o *ObjectController) Put() { - objectId := o.Ctx.Input.Params[":objectId"] + objectId := o.Ctx.Input.Param(":objectId") var ob models.Object json.Unmarshal(o.Ctx.Input.RequestBody, &ob) @@ -370,7 +370,7 @@ func (o *ObjectController) Put() { // @Failure 403 objectId is empty // @router /:objectId [delete] func (o *ObjectController) Delete() { - objectId := o.Ctx.Input.Params[":objectId"] + objectId := o.Ctx.Input.Param(":objectId") models.Delete(objectId) o.Data["json"] = "delete success!" o.ServeJSON() diff --git a/bee.go b/bee.go index 6f4b4f6..dcc9d14 100644 --- a/bee.go +++ b/bee.go @@ -85,6 +85,7 @@ var commands = []*Command{ cmdGenerate, //cmdRundocs, cmdMigrate, + cmdFix, } func main() { diff --git a/fix.go b/fix.go new file mode 100644 index 0000000..e572b7c --- /dev/null +++ b/fix.go @@ -0,0 +1,19 @@ +package main + +var cmdFix = &Command{ + UsageLine: "fix", + Short: "fix the beego application to compatibel with beego 1.6", + Long: ` +As from beego1.6, there's some incompatible code with the old version. + +bee fix help to upgrade the application to beego 1.6 +`, +} + +func init() { + cmdFix.Run = runFix +} + +func runFix(cmd *Command, args []string) int { + return 0 +} diff --git a/g_appcode.go b/g_appcode.go index 81d6213..228b9c2 100644 --- a/g_appcode.go +++ b/g_appcode.go @@ -1192,7 +1192,7 @@ func (c *{{ctrlName}}Controller) Post() { // @Failure 403 :id is empty // @router /:id [get] func (c *{{ctrlName}}Controller) GetOne() { - idStr := c.Ctx.Input.Params[":id"] + idStr := c.Ctx.Input.Param(":id") id, _ := strconv.Atoi(idStr) v, err := models.Get{{ctrlName}}ById(id) if err != nil { @@ -1273,7 +1273,7 @@ func (c *{{ctrlName}}Controller) GetAll() { // @Failure 403 :id is not int // @router /:id [put] func (c *{{ctrlName}}Controller) Put() { - idStr := c.Ctx.Input.Params[":id"] + idStr := c.Ctx.Input.Param(":id") id, _ := strconv.Atoi(idStr) v := models.{{ctrlName}}{Id: id} if err := json.Unmarshal(c.Ctx.Input.RequestBody, &v); err == nil { @@ -1295,7 +1295,7 @@ func (c *{{ctrlName}}Controller) Put() { // @Failure 403 id is empty // @router /:id [delete] func (c *{{ctrlName}}Controller) Delete() { - idStr := c.Ctx.Input.Params[":id"] + idStr := c.Ctx.Input.Param(":id") id, _ := strconv.Atoi(idStr) if err := models.Delete{{ctrlName}}(id); err == nil { c.Data["json"] = "OK" diff --git a/g_controllers.go b/g_controllers.go index 57f2e02..49b5fd9 100644 --- a/g_controllers.go +++ b/g_controllers.go @@ -192,7 +192,7 @@ func (c *{{controllerName}}Controller) Post() { // @Failure 403 :id is empty // @router /:id [get] func (c *{{controllerName}}Controller) GetOne() { - idStr := c.Ctx.Input.Params[":id"] + idStr := c.Ctx.Input.Param(":id") id, _ := strconv.ParseInt(idStr, 0, 64) v, err := models.Get{{controllerName}}ById(id) if err != nil { @@ -273,7 +273,7 @@ func (c *{{controllerName}}Controller) GetAll() { // @Failure 403 :id is not int // @router /:id [put] func (c *{{controllerName}}Controller) Put() { - idStr := c.Ctx.Input.Params[":id"] + idStr := c.Ctx.Input.Param(":id") id, _ := strconv.ParseInt(idStr, 0, 64) v := models.{{controllerName}}{Id: id} json.Unmarshal(c.Ctx.Input.RequestBody, &v) @@ -292,7 +292,7 @@ func (c *{{controllerName}}Controller) Put() { // @Failure 403 id is empty // @router /:id [delete] func (c *{{controllerName}}Controller) Delete() { - idStr := c.Ctx.Input.Params[":id"] + idStr := c.Ctx.Input.Param(":id") id, _ := strconv.ParseInt(idStr, 0, 64) if err := models.Delete{{controllerName}}(id); err == nil { c.Data["json"] = "OK" diff --git a/g_docs.go b/g_docs.go index 6da36ce..fb11bcd 100644 --- a/g_docs.go +++ b/g_docs.go @@ -55,7 +55,7 @@ var rootapi swagger.ResourceListing var apilist map[string]*swagger.APIDeclaration func init() { - if beego.EnableDocs { + if beego.Bconfig.WebConifg.EnableDocs { err := json.Unmarshal([]byte(Rootinfo), &rootapi) if err != nil { beego.Error(err)