2019-02-02 16:18:25 +08:00
|
|
|
// Copyright 2017 gf Author(https://github.com/gogf/gf). All Rights Reserved.
|
2018-07-29 22:01:29 +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-07-29 22:01:29 +08:00
|
|
|
|
|
|
|
|
package ghttp
|
|
|
|
|
|
2019-09-18 23:20:45 +08:00
|
|
|
import "github.com/gogf/gf/container/gvar"
|
2018-07-31 21:05:02 +08:00
|
|
|
|
2019-12-03 17:16:52 +08:00
|
|
|
// GetRouterValue retrieves and returns the router value with given key name <key>.
|
|
|
|
|
// It returns <def> if <key> does not exist.
|
2019-09-18 23:20:45 +08:00
|
|
|
func (r *Request) GetRouterValue(key string, def ...interface{}) interface{} {
|
|
|
|
|
if r.routerMap != nil {
|
2020-01-08 20:00:42 +08:00
|
|
|
if v, ok := r.routerMap[key]; ok {
|
|
|
|
|
return v
|
|
|
|
|
}
|
2019-06-19 09:06:52 +08:00
|
|
|
}
|
2019-09-18 23:20:45 +08:00
|
|
|
if len(def) > 0 {
|
|
|
|
|
return def[0]
|
2019-06-19 09:06:52 +08:00
|
|
|
}
|
|
|
|
|
return nil
|
2018-07-29 22:01:29 +08:00
|
|
|
}
|
2019-09-18 23:20:45 +08:00
|
|
|
|
2019-12-03 17:16:52 +08:00
|
|
|
// GetRouterVar retrieves and returns the router value as *gvar.var with given key name <key>.
|
|
|
|
|
// It returns <def> if <key> does not exist.
|
2019-09-18 23:20:45 +08:00
|
|
|
func (r *Request) GetRouterVar(key string, def ...interface{}) *gvar.Var {
|
|
|
|
|
return gvar.New(r.GetRouterValue(key, def...))
|
|
|
|
|
}
|
2019-09-19 19:44:46 +08:00
|
|
|
|
2019-12-03 17:16:52 +08:00
|
|
|
// GetRouterString retrieves and returns the router value as string with given key name <key>.
|
|
|
|
|
// It returns <def> if <key> does not exist.
|
2019-09-19 19:44:46 +08:00
|
|
|
func (r *Request) GetRouterString(key string, def ...interface{}) string {
|
|
|
|
|
return r.GetRouterVar(key, def...).String()
|
|
|
|
|
}
|