some misstakes on creating api app

This commit is contained in:
Xuyuan Pang 2013-09-13 15:32:58 +08:00
parent 550cf6cb71
commit e8df0b125f
1 changed files with 11 additions and 11 deletions

View File

@ -53,8 +53,8 @@ import (
// /object/<objectId> DELETE Deleting Objects // /object/<objectId> DELETE Deleting Objects
func main() { func main() {
beego.RESTRouter("/object", &controllers.ObejctController{}) beego.RESTRouter("/object", &controllers.ObjectController{})
beego.Router("/ping", &controllers.ObejctController{},"get:Ping") beego.Router("/ping", &controllers.ObjectController{},"get:Ping")
beego.Run() beego.Run()
} }
` `
@ -123,11 +123,11 @@ import (
type ResponseInfo struct { type ResponseInfo struct {
} }
type ObejctController struct { type ObjectController struct {
beego.Controller beego.Controller
} }
func (this *ObejctController) Post() { func (this *ObjectController) Post() {
var ob models.Object var ob models.Object
json.Unmarshal(this.Ctx.Input.RequestBody, &ob) json.Unmarshal(this.Ctx.Input.RequestBody, &ob)
objectid := models.AddOne(ob) objectid := models.AddOne(ob)
@ -135,8 +135,8 @@ func (this *ObejctController) Post() {
this.ServeJson() this.ServeJson()
} }
func (this *ObejctController) Get() { func (this *ObjectController) Get() {
objectId := this.Ctx.Params[":objectId"] objectId := this.Ctx.Input.Param[":objectId"]
if objectId != "" { if objectId != "" {
ob, err := models.GetOne(objectId) ob, err := models.GetOne(objectId)
if err != nil { if err != nil {
@ -151,8 +151,8 @@ func (this *ObejctController) Get() {
this.ServeJson() this.ServeJson()
} }
func (this *ObejctController) Put() { func (this *ObjectController) Put() {
objectId := this.Ctx.Params[":objectId"] objectId := this.Ctx.Input.Param[":objectId"]
var ob models.Object var ob models.Object
json.Unmarshal(this.Ctx.Input.RequestBody, &ob) json.Unmarshal(this.Ctx.Input.RequestBody, &ob)
@ -165,14 +165,14 @@ func (this *ObejctController) Put() {
this.ServeJson() this.ServeJson()
} }
func (this *ObejctController) Delete() { func (this *ObjectController) Delete() {
objectId := this.Ctx.Input.Params[":objectId"] objectId := this.Ctx.Input.Param[":objectId"]
models.Delete(objectId) models.Delete(objectId)
this.Data["json"] = "delete success!" this.Data["json"] = "delete success!"
this.ServeJson() this.ServeJson()
} }
func (this *ObejctController) Ping() { func (this *ObjectController) Ping() {
this.Ctx.WriteString("pong") this.Ctx.WriteString("pong")
} }