2019-02-02 16:18:25 +08:00
|
|
|
// Copyright 2017 gf Author(https://github.com/gogf/gf). All Rights Reserved.
|
2018-11-19 21:11:43 +08:00
|
|
|
//
|
|
|
|
// This Source Code Form is subject to the terms of the MIT License.
|
|
|
|
// If a copy of the MIT was not distributed with this file,
|
2019-02-02 16:18:25 +08:00
|
|
|
// You can obtain one at https://github.com/gogf/gf.
|
2018-11-19 21:11:43 +08:00
|
|
|
|
|
|
|
package ghttp
|
|
|
|
|
2019-07-29 21:01:19 +08:00
|
|
|
import "github.com/gogf/gf/container/gvar"
|
2018-11-19 21:11:43 +08:00
|
|
|
|
|
|
|
// 设置请求流程共享变量
|
|
|
|
func (r *Request) SetParam(key string, value interface{}) {
|
2019-06-19 09:06:52 +08:00
|
|
|
if r.params == nil {
|
|
|
|
r.params = make(map[string]interface{})
|
|
|
|
}
|
|
|
|
r.params[key] = value
|
2018-11-19 21:11:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// 获取请求流程共享变量
|
2019-06-19 09:06:52 +08:00
|
|
|
func (r *Request) GetParam(key string, def ...interface{}) *gvar.Var {
|
|
|
|
if r.params != nil {
|
|
|
|
if v, ok := r.params[key]; ok {
|
2019-07-23 23:20:27 +08:00
|
|
|
return gvar.New(v)
|
2019-06-19 09:06:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(def) > 0 {
|
2019-07-23 23:20:27 +08:00
|
|
|
return gvar.New(def[0])
|
2019-06-19 09:06:52 +08:00
|
|
|
}
|
2019-07-23 23:20:27 +08:00
|
|
|
return gvar.New(nil)
|
2018-11-19 21:11:43 +08:00
|
|
|
}
|