ae2e25f4 by astaxie

fix #316

1 parent 7b405e9a
1 package context 1 package context
2 2
3 import ( 3 import (
4 "net/http"
5
6 "github.com/astaxie/beego/middleware" 4 "github.com/astaxie/beego/middleware"
5 "net/http"
7 ) 6 )
8 7
9 type Context struct { 8 type Context struct {
...@@ -22,12 +21,12 @@ func (ctx *Context) Abort(status int, body string) { ...@@ -22,12 +21,12 @@ func (ctx *Context) Abort(status int, body string) {
22 ctx.Output.SetStatus(status) 21 ctx.Output.SetStatus(status)
23 ctx.Output.Body([]byte(body)) 22 ctx.Output.Body([]byte(body))
24 23
25 if e, ok := middleware.HTTPExceptionMaps[status]; ok { 24 if e, ok := middleware.HTTPExceptionMaps[status]; ok {
26 if len(body) >= 1 { 25 if len(body) >= 1 {
27 e.Description = body 26 e.Description = body
28 } 27 }
29 panic(e) 28 panic(e)
30 } 29 }
31 } 30 }
32 31
33 func (ctx *Context) WriteString(content string) { 32 func (ctx *Context) WriteString(content string) {
......
...@@ -11,15 +11,17 @@ import ( ...@@ -11,15 +11,17 @@ import (
11 11
12 type BeegoInput struct { 12 type BeegoInput struct {
13 CruSession session.SessionStore 13 CruSession session.SessionStore
14 Param map[string]string 14 Params map[string]string
15 Data map[interface{}]interface{}
15 req *http.Request 16 req *http.Request
16 RequestBody []byte 17 RequestBody []byte
17 } 18 }
18 19
19 func NewInput(req *http.Request) *BeegoInput { 20 func NewInput(req *http.Request) *BeegoInput {
20 return &BeegoInput{ 21 return &BeegoInput{
21 Param: make(map[string]string), 22 Params: make(map[string]string),
22 req: req, 23 Data: make(map[interface{}]interface{}),
24 req: req,
23 } 25 }
24 } 26 }
25 27
...@@ -129,8 +131,8 @@ func (input *BeegoInput) UserAgent() string { ...@@ -129,8 +131,8 @@ func (input *BeegoInput) UserAgent() string {
129 return input.Header("User-Agent") 131 return input.Header("User-Agent")
130 } 132 }
131 133
132 func (input *BeegoInput) Params(key string) string { 134 func (input *BeegoInput) Param(key string) string {
133 if v, ok := input.Param[key]; ok { 135 if v, ok := input.Params[key]; ok {
134 return v 136 return v
135 } 137 }
136 return "" 138 return ""
...@@ -164,3 +166,14 @@ func (input *BeegoInput) Body() []byte { ...@@ -164,3 +166,14 @@ func (input *BeegoInput) Body() []byte {
164 input.RequestBody = requestbody 166 input.RequestBody = requestbody
165 return requestbody 167 return requestbody
166 } 168 }
169
170 func (input *BeegoInput) GetData(key interface{}) interface{} {
171 if v, ok := input.Data[key]; ok {
172 return v
173 }
174 return nil
175 }
176
177 func (input *BeegoInput) SetData(key, val interface{}) {
178 input.Data[key] = val
179 }
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!