Commit ae2e25f4 authored by astaxie's avatar astaxie

fix #316

parent 7b405e9a
package context package context
import ( import (
"net/http"
"github.com/astaxie/beego/middleware" "github.com/astaxie/beego/middleware"
"net/http"
) )
type Context struct { 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) {
ctx.Output.SetStatus(status) ctx.Output.SetStatus(status)
ctx.Output.Body([]byte(body)) ctx.Output.Body([]byte(body))
if e, ok := middleware.HTTPExceptionMaps[status]; ok { if e, ok := middleware.HTTPExceptionMaps[status]; ok {
if len(body) >= 1 { if len(body) >= 1 {
e.Description = body e.Description = body
} }
panic(e) panic(e)
} }
} }
func (ctx *Context) WriteString(content string) { func (ctx *Context) WriteString(content string) {
......
...@@ -11,15 +11,17 @@ import ( ...@@ -11,15 +11,17 @@ import (
type BeegoInput struct { type BeegoInput struct {
CruSession session.SessionStore CruSession session.SessionStore
Param map[string]string Params map[string]string
Data map[interface{}]interface{}
req *http.Request req *http.Request
RequestBody []byte RequestBody []byte
} }
func NewInput(req *http.Request) *BeegoInput { func NewInput(req *http.Request) *BeegoInput {
return &BeegoInput{ return &BeegoInput{
Param: make(map[string]string), Params: make(map[string]string),
req: req, Data: make(map[interface{}]interface{}),
req: req,
} }
} }
...@@ -129,8 +131,8 @@ func (input *BeegoInput) UserAgent() string { ...@@ -129,8 +131,8 @@ func (input *BeegoInput) UserAgent() string {
return input.Header("User-Agent") return input.Header("User-Agent")
} }
func (input *BeegoInput) Params(key string) string { func (input *BeegoInput) Param(key string) string {
if v, ok := input.Param[key]; ok { if v, ok := input.Params[key]; ok {
return v return v
} }
return "" return ""
...@@ -164,3 +166,14 @@ func (input *BeegoInput) Body() []byte { ...@@ -164,3 +166,14 @@ func (input *BeegoInput) Body() []byte {
input.RequestBody = requestbody input.RequestBody = requestbody
return requestbody return requestbody
} }
func (input *BeegoInput) GetData(key interface{}) interface{} {
if v, ok := input.Data[key]; ok {
return v
}
return nil
}
func (input *BeegoInput) SetData(key, val interface{}) {
input.Data[key] = val
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment