gf/net/ghttp/ghttp_request_params.go

31 lines
772 B
Go
Raw Normal View History

// Copyright 2017 gf Author(https://github.com/gogf/gf). All Rights Reserved.
//
// 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,
// You can obtain one at https://github.com/gogf/gf.
package ghttp
2019-07-29 21:01:19 +08:00
import "github.com/gogf/gf/container/gvar"
// 设置请求流程共享变量
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
}
// 获取请求流程共享变量
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 {
return gvar.New(v)
2019-06-19 09:06:52 +08:00
}
}
if len(def) > 0 {
return gvar.New(def[0])
2019-06-19 09:06:52 +08:00
}
return gvar.New(nil)
}