github.com/zhongdalu/gf@v1.0.0/g/net/ghttp/ghttp_request_params.go (about) 1 // Copyright 2017 gf Author(https://github.com/zhongdalu/gf). All Rights Reserved. 2 // 3 // This Source Code Form is subject to the terms of the MIT License. 4 // If a copy of the MIT was not distributed with this file, 5 // You can obtain one at https://github.com/zhongdalu/gf. 6 7 package ghttp 8 9 import "github.com/zhongdalu/gf/g/container/gvar" 10 11 // 设置请求流程共享变量 12 func (r *Request) SetParam(key string, value interface{}) { 13 if r.params == nil { 14 r.params = make(map[string]interface{}) 15 } 16 r.params[key] = value 17 } 18 19 // 获取请求流程共享变量 20 func (r *Request) GetParam(key string, def ...interface{}) *gvar.Var { 21 if r.params != nil { 22 if v, ok := r.params[key]; ok { 23 return gvar.New(v, true) 24 } 25 } 26 if len(def) > 0 { 27 return gvar.New(def[0], true) 28 } 29 return gvar.New(nil, true) 30 }