1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-22 14:00:54 +00:00

change this to short name

This commit is contained in:
astaxie 2014-11-05 22:40:31 +08:00
parent 950ff91d87
commit 54ba307f7f
5 changed files with 44 additions and 44 deletions

View File

@ -17,47 +17,47 @@ type ObjectController struct {
beego.Controller beego.Controller
} }
func (this *ObjectController) Post() { func (o *ObjectController) Post() {
var ob models.Object var ob models.Object
json.Unmarshal(this.Ctx.Input.RequestBody, &ob) json.Unmarshal(o.Ctx.Input.RequestBody, &ob)
objectid := models.AddOne(ob) objectid := models.AddOne(ob)
this.Data["json"] = map[string]string{"ObjectId": objectid} o.Data["json"] = map[string]string{"ObjectId": objectid}
this.ServeJson() o.ServeJson()
} }
func (this *ObjectController) Get() { func (o *ObjectController) Get() {
objectId := this.Ctx.Input.Params[":objectId"] objectId := o.Ctx.Input.Params[":objectId"]
if objectId != "" { if objectId != "" {
ob, err := models.GetOne(objectId) ob, err := models.GetOne(objectId)
if err != nil { if err != nil {
this.Data["json"] = err o.Data["json"] = err
} else { } else {
this.Data["json"] = ob o.Data["json"] = ob
} }
} else { } else {
obs := models.GetAll() obs := models.GetAll()
this.Data["json"] = obs o.Data["json"] = obs
} }
this.ServeJson() o.ServeJson()
} }
func (this *ObjectController) Put() { func (o *ObjectController) Put() {
objectId := this.Ctx.Input.Params[":objectId"] objectId := o.Ctx.Input.Params[":objectId"]
var ob models.Object var ob models.Object
json.Unmarshal(this.Ctx.Input.RequestBody, &ob) json.Unmarshal(o.Ctx.Input.RequestBody, &ob)
err := models.Update(objectId, ob.Score) err := models.Update(objectId, ob.Score)
if err != nil { if err != nil {
this.Data["json"] = err o.Data["json"] = err
} else { } else {
this.Data["json"] = "update success!" o.Data["json"] = "update success!"
} }
this.ServeJson() o.ServeJson()
} }
func (this *ObjectController) Delete() { func (o *ObjectController) Delete() {
objectId := this.Ctx.Input.Params[":objectId"] objectId := o.Ctx.Input.Params[":objectId"]
models.Delete(objectId) models.Delete(objectId)
this.Data["json"] = "delete success!" o.Data["json"] = "delete success!"
this.ServeJson() o.ServeJson()
} }

View File

@ -14,7 +14,7 @@ type MainController struct {
beego.Controller beego.Controller
} }
func (this *MainController) Get() { func (m *MainController) Get() {
this.Data["host"] = this.Ctx.Request.Host m.Data["host"] = m.Ctx.Request.Host
this.TplNames = "index.tpl" m.TplNames = "index.tpl"
} }

View File

@ -154,10 +154,10 @@ var upgrader = websocket.Upgrader{
WriteBufferSize: 1024, WriteBufferSize: 1024,
} }
func (this *WSController) Get() { func (w *WSController) Get() {
ws, err := upgrader.Upgrade(this.Ctx.ResponseWriter, this.Ctx.Request, nil) ws, err := upgrader.Upgrade(w.Ctx.ResponseWriter, w.Ctx.Request, nil)
if _, ok := err.(websocket.HandshakeError); ok { if _, ok := err.(websocket.HandshakeError); ok {
http.Error(this.Ctx.ResponseWriter, "Not a websocket handshake", 400) http.Error(w.Ctx.ResponseWriter, "Not a websocket handshake", 400)
return return
} else if err != nil { } else if err != nil {
return return

View File

@ -25,12 +25,12 @@ type TestFlashController struct {
Controller Controller
} }
func (this *TestFlashController) TestWriteFlash() { func (t *TestFlashController) TestWriteFlash() {
flash := NewFlash() flash := NewFlash()
flash.Notice("TestFlashString") flash.Notice("TestFlashString")
flash.Store(&this.Controller) flash.Store(&t.Controller)
// we choose to serve json because we don't want to load a template html file // we choose to serve json because we don't want to load a template html file
this.ServeJson(true) t.ServeJson(true)
} }
func TestFlashHeader(t *testing.T) { func TestFlashHeader(t *testing.T) {

View File

@ -27,33 +27,33 @@ type TestController struct {
Controller Controller
} }
func (this *TestController) Get() { func (tc *TestController) Get() {
this.Data["Username"] = "astaxie" tc.Data["Username"] = "astaxie"
this.Ctx.Output.Body([]byte("ok")) tc.Ctx.Output.Body([]byte("ok"))
} }
func (this *TestController) Post() { func (tc *TestController) Post() {
this.Ctx.Output.Body([]byte(this.Ctx.Input.Query(":name"))) tc.Ctx.Output.Body([]byte(tc.Ctx.Input.Query(":name")))
} }
func (this *TestController) Param() { func (tc *TestController) Param() {
this.Ctx.Output.Body([]byte(this.Ctx.Input.Query(":name"))) tc.Ctx.Output.Body([]byte(tc.Ctx.Input.Query(":name")))
} }
func (this *TestController) List() { func (tc *TestController) List() {
this.Ctx.Output.Body([]byte("i am list")) tc.Ctx.Output.Body([]byte("i am list"))
} }
func (this *TestController) Params() { func (tc *TestController) Params() {
this.Ctx.Output.Body([]byte(this.Ctx.Input.Params["0"] + this.Ctx.Input.Params["1"] + this.Ctx.Input.Params["2"])) tc.Ctx.Output.Body([]byte(tc.Ctx.Input.Params["0"] + tc.Ctx.Input.Params["1"] + tc.Ctx.Input.Params["2"]))
} }
func (this *TestController) Myext() { func (tc *TestController) Myext() {
this.Ctx.Output.Body([]byte(this.Ctx.Input.Param(":ext"))) tc.Ctx.Output.Body([]byte(tc.Ctx.Input.Param(":ext")))
} }
func (this *TestController) GetUrl() { func (tc *TestController) GetUrl() {
this.Ctx.Output.Body([]byte(this.UrlFor(".Myext"))) tc.Ctx.Output.Body([]byte(tc.UrlFor(".Myext")))
} }
func (t *TestController) GetParams() { func (t *TestController) GetParams() {