添加setparams传递
This commit is contained in:
parent
42c1356a54
commit
082a0f69f7
|
@ -8,6 +8,7 @@ import (
|
|||
"gitee.com/zhucheer/orange/request"
|
||||
"gitee.com/zhucheer/orange/session"
|
||||
"net/http"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type Context struct {
|
||||
|
@ -18,6 +19,8 @@ type Context struct {
|
|||
responseBody bytes.Buffer
|
||||
OrangeInput *request.OrangeInput
|
||||
CsrfToken string
|
||||
userParams map[string]interface{}
|
||||
mutx sync.Mutex
|
||||
}
|
||||
|
||||
func NewCtx(ctx context.Context, w http.ResponseWriter, r *http.Request) *Context {
|
||||
|
@ -54,6 +57,26 @@ func (c *Context) Session() session.Store {
|
|||
return c.session
|
||||
}
|
||||
|
||||
func (c *Context) SetCtxParam(key string, value interface{}) {
|
||||
c.mutx.Lock()
|
||||
defer c.mutx.Unlock()
|
||||
|
||||
if c.userParams == nil {
|
||||
c.userParams = make(map[string]interface{})
|
||||
}
|
||||
c.userParams[key] = value
|
||||
}
|
||||
|
||||
func (c *Context) GetCtxParam(key string) (val interface{}) {
|
||||
if c.userParams == nil {
|
||||
return
|
||||
}
|
||||
if val, ok := c.userParams[key]; ok {
|
||||
return val
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (c *Context) SetCookie(cookie *http.Cookie) {
|
||||
http.SetCookie(c.response, cookie)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue