mirror of
https://github.com/beego/bee.git
synced 2024-12-22 15:10:49 +00:00
some misstakes on creating api app
This commit is contained in:
parent
550cf6cb71
commit
e8df0b125f
22
apiapp.go
22
apiapp.go
@ -53,8 +53,8 @@ import (
|
||||
// /object/<objectId> DELETE Deleting Objects
|
||||
|
||||
func main() {
|
||||
beego.RESTRouter("/object", &controllers.ObejctController{})
|
||||
beego.Router("/ping", &controllers.ObejctController{},"get:Ping")
|
||||
beego.RESTRouter("/object", &controllers.ObjectController{})
|
||||
beego.Router("/ping", &controllers.ObjectController{},"get:Ping")
|
||||
beego.Run()
|
||||
}
|
||||
`
|
||||
@ -123,11 +123,11 @@ import (
|
||||
type ResponseInfo struct {
|
||||
}
|
||||
|
||||
type ObejctController struct {
|
||||
type ObjectController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
func (this *ObejctController) Post() {
|
||||
func (this *ObjectController) Post() {
|
||||
var ob models.Object
|
||||
json.Unmarshal(this.Ctx.Input.RequestBody, &ob)
|
||||
objectid := models.AddOne(ob)
|
||||
@ -135,8 +135,8 @@ func (this *ObejctController) Post() {
|
||||
this.ServeJson()
|
||||
}
|
||||
|
||||
func (this *ObejctController) Get() {
|
||||
objectId := this.Ctx.Params[":objectId"]
|
||||
func (this *ObjectController) Get() {
|
||||
objectId := this.Ctx.Input.Param[":objectId"]
|
||||
if objectId != "" {
|
||||
ob, err := models.GetOne(objectId)
|
||||
if err != nil {
|
||||
@ -151,8 +151,8 @@ func (this *ObejctController) Get() {
|
||||
this.ServeJson()
|
||||
}
|
||||
|
||||
func (this *ObejctController) Put() {
|
||||
objectId := this.Ctx.Params[":objectId"]
|
||||
func (this *ObjectController) Put() {
|
||||
objectId := this.Ctx.Input.Param[":objectId"]
|
||||
var ob models.Object
|
||||
json.Unmarshal(this.Ctx.Input.RequestBody, &ob)
|
||||
|
||||
@ -165,14 +165,14 @@ func (this *ObejctController) Put() {
|
||||
this.ServeJson()
|
||||
}
|
||||
|
||||
func (this *ObejctController) Delete() {
|
||||
objectId := this.Ctx.Input.Params[":objectId"]
|
||||
func (this *ObjectController) Delete() {
|
||||
objectId := this.Ctx.Input.Param[":objectId"]
|
||||
models.Delete(objectId)
|
||||
this.Data["json"] = "delete success!"
|
||||
this.ServeJson()
|
||||
}
|
||||
|
||||
func (this *ObejctController) Ping() {
|
||||
func (this *ObjectController) Ping() {
|
||||
this.Ctx.WriteString("pong")
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user