2021-01-17 21:46:25 +08:00
|
|
|
// Copyright GoFrame Author(https://goframe.org). 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
|
|
|
|
2020-08-12 21:01:17 +08:00
|
|
|
// GetRouterMap retrieves and returns a copy of router map.
|
|
|
|
func (r *Request) GetRouterMap() map[string]string {
|
|
|
|
if r.routerMap != nil {
|
|
|
|
m := make(map[string]string, len(r.routerMap))
|
|
|
|
for k, v := range r.routerMap {
|
|
|
|
m[k] = v
|
|
|
|
}
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-09-27 21:27:24 +08:00
|
|
|
// GetRouter retrieves and returns the router value with given key name <key>.
|
2019-12-03 17:16:52 +08:00
|
|
|
// It returns <def> if <key> does not exist.
|
2021-09-27 21:27:24 +08:00
|
|
|
func (r *Request) GetRouter(key string, def ...interface{}) *gvar.Var {
|
2019-09-18 23:20:45 +08:00
|
|
|
if r.routerMap != nil {
|
2020-01-08 20:00:42 +08:00
|
|
|
if v, ok := r.routerMap[key]; ok {
|
2021-09-27 21:27:24 +08:00
|
|
|
return gvar.New(v)
|
2020-01-08 20:00:42 +08:00
|
|
|
}
|
2019-06-19 09:06:52 +08:00
|
|
|
}
|
2019-09-18 23:20:45 +08:00
|
|
|
if len(def) > 0 {
|
2021-09-27 21:27:24 +08:00
|
|
|
return gvar.New(def[0])
|
2019-06-19 09:06:52 +08:00
|
|
|
}
|
|
|
|
return nil
|
2018-07-29 22:01:29 +08:00
|
|
|
}
|