54ba307f by astaxie

change this to short name

1 parent 950ff91d
...@@ -17,47 +17,47 @@ type ObjectController struct { ...@@ -17,47 +17,47 @@ type ObjectController struct {
17 beego.Controller 17 beego.Controller
18 } 18 }
19 19
20 func (this *ObjectController) Post() { 20 func (o *ObjectController) Post() {
21 var ob models.Object 21 var ob models.Object
22 json.Unmarshal(this.Ctx.Input.RequestBody, &ob) 22 json.Unmarshal(o.Ctx.Input.RequestBody, &ob)
23 objectid := models.AddOne(ob) 23 objectid := models.AddOne(ob)
24 this.Data["json"] = map[string]string{"ObjectId": objectid} 24 o.Data["json"] = map[string]string{"ObjectId": objectid}
25 this.ServeJson() 25 o.ServeJson()
26 } 26 }
27 27
28 func (this *ObjectController) Get() { 28 func (o *ObjectController) Get() {
29 objectId := this.Ctx.Input.Params[":objectId"] 29 objectId := o.Ctx.Input.Params[":objectId"]
30 if objectId != "" { 30 if objectId != "" {
31 ob, err := models.GetOne(objectId) 31 ob, err := models.GetOne(objectId)
32 if err != nil { 32 if err != nil {
33 this.Data["json"] = err 33 o.Data["json"] = err
34 } else { 34 } else {
35 this.Data["json"] = ob 35 o.Data["json"] = ob
36 } 36 }
37 } else { 37 } else {
38 obs := models.GetAll() 38 obs := models.GetAll()
39 this.Data["json"] = obs 39 o.Data["json"] = obs
40 } 40 }
41 this.ServeJson() 41 o.ServeJson()
42 } 42 }
43 43
44 func (this *ObjectController) Put() { 44 func (o *ObjectController) Put() {
45 objectId := this.Ctx.Input.Params[":objectId"] 45 objectId := o.Ctx.Input.Params[":objectId"]
46 var ob models.Object 46 var ob models.Object
47 json.Unmarshal(this.Ctx.Input.RequestBody, &ob) 47 json.Unmarshal(o.Ctx.Input.RequestBody, &ob)
48 48
49 err := models.Update(objectId, ob.Score) 49 err := models.Update(objectId, ob.Score)
50 if err != nil { 50 if err != nil {
51 this.Data["json"] = err 51 o.Data["json"] = err
52 } else { 52 } else {
53 this.Data["json"] = "update success!" 53 o.Data["json"] = "update success!"
54 } 54 }
55 this.ServeJson() 55 o.ServeJson()
56 } 56 }
57 57
58 func (this *ObjectController) Delete() { 58 func (o *ObjectController) Delete() {
59 objectId := this.Ctx.Input.Params[":objectId"] 59 objectId := o.Ctx.Input.Params[":objectId"]
60 models.Delete(objectId) 60 models.Delete(objectId)
61 this.Data["json"] = "delete success!" 61 o.Data["json"] = "delete success!"
62 this.ServeJson() 62 o.ServeJson()
63 } 63 }
......
...@@ -14,7 +14,7 @@ type MainController struct { ...@@ -14,7 +14,7 @@ type MainController struct {
14 beego.Controller 14 beego.Controller
15 } 15 }
16 16
17 func (this *MainController) Get() { 17 func (m *MainController) Get() {
18 this.Data["host"] = this.Ctx.Request.Host 18 m.Data["host"] = m.Ctx.Request.Host
19 this.TplNames = "index.tpl" 19 m.TplNames = "index.tpl"
20 } 20 }
......
...@@ -154,10 +154,10 @@ var upgrader = websocket.Upgrader{ ...@@ -154,10 +154,10 @@ var upgrader = websocket.Upgrader{
154 WriteBufferSize: 1024, 154 WriteBufferSize: 1024,
155 } 155 }
156 156
157 func (this *WSController) Get() { 157 func (w *WSController) Get() {
158 ws, err := upgrader.Upgrade(this.Ctx.ResponseWriter, this.Ctx.Request, nil) 158 ws, err := upgrader.Upgrade(w.Ctx.ResponseWriter, w.Ctx.Request, nil)
159 if _, ok := err.(websocket.HandshakeError); ok { 159 if _, ok := err.(websocket.HandshakeError); ok {
160 http.Error(this.Ctx.ResponseWriter, "Not a websocket handshake", 400) 160 http.Error(w.Ctx.ResponseWriter, "Not a websocket handshake", 400)
161 return 161 return
162 } else if err != nil { 162 } else if err != nil {
163 return 163 return
......
...@@ -25,12 +25,12 @@ type TestFlashController struct { ...@@ -25,12 +25,12 @@ type TestFlashController struct {
25 Controller 25 Controller
26 } 26 }
27 27
28 func (this *TestFlashController) TestWriteFlash() { 28 func (t *TestFlashController) TestWriteFlash() {
29 flash := NewFlash() 29 flash := NewFlash()
30 flash.Notice("TestFlashString") 30 flash.Notice("TestFlashString")
31 flash.Store(&this.Controller) 31 flash.Store(&t.Controller)
32 // we choose to serve json because we don't want to load a template html file 32 // we choose to serve json because we don't want to load a template html file
33 this.ServeJson(true) 33 t.ServeJson(true)
34 } 34 }
35 35
36 func TestFlashHeader(t *testing.T) { 36 func TestFlashHeader(t *testing.T) {
......
...@@ -27,33 +27,33 @@ type TestController struct { ...@@ -27,33 +27,33 @@ type TestController struct {
27 Controller 27 Controller
28 } 28 }
29 29
30 func (this *TestController) Get() { 30 func (tc *TestController) Get() {
31 this.Data["Username"] = "astaxie" 31 tc.Data["Username"] = "astaxie"
32 this.Ctx.Output.Body([]byte("ok")) 32 tc.Ctx.Output.Body([]byte("ok"))
33 } 33 }
34 34
35 func (this *TestController) Post() { 35 func (tc *TestController) Post() {
36 this.Ctx.Output.Body([]byte(this.Ctx.Input.Query(":name"))) 36 tc.Ctx.Output.Body([]byte(tc.Ctx.Input.Query(":name")))
37 } 37 }
38 38
39 func (this *TestController) Param() { 39 func (tc *TestController) Param() {
40 this.Ctx.Output.Body([]byte(this.Ctx.Input.Query(":name"))) 40 tc.Ctx.Output.Body([]byte(tc.Ctx.Input.Query(":name")))
41 } 41 }
42 42
43 func (this *TestController) List() { 43 func (tc *TestController) List() {
44 this.Ctx.Output.Body([]byte("i am list")) 44 tc.Ctx.Output.Body([]byte("i am list"))
45 } 45 }
46 46
47 func (this *TestController) Params() { 47 func (tc *TestController) Params() {
48 this.Ctx.Output.Body([]byte(this.Ctx.Input.Params["0"] + this.Ctx.Input.Params["1"] + this.Ctx.Input.Params["2"])) 48 tc.Ctx.Output.Body([]byte(tc.Ctx.Input.Params["0"] + tc.Ctx.Input.Params["1"] + tc.Ctx.Input.Params["2"]))
49 } 49 }
50 50
51 func (this *TestController) Myext() { 51 func (tc *TestController) Myext() {
52 this.Ctx.Output.Body([]byte(this.Ctx.Input.Param(":ext"))) 52 tc.Ctx.Output.Body([]byte(tc.Ctx.Input.Param(":ext")))
53 } 53 }
54 54
55 func (this *TestController) GetUrl() { 55 func (tc *TestController) GetUrl() {
56 this.Ctx.Output.Body([]byte(this.UrlFor(".Myext"))) 56 tc.Ctx.Output.Body([]byte(tc.UrlFor(".Myext")))
57 } 57 }
58 58
59 func (t *TestController) GetParams() { 59 func (t *TestController) GetParams() {
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!