gf/net/ghttp/ghttp_request_param_router.go

36 lines
931 B
Go
Raw Normal View History

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,
// You can obtain one at https://github.com/gogf/gf.
2018-07-29 22:01:29 +08:00
package ghttp
import "github.com/gogf/gf/container/gvar"
// 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>.
// 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 {
if r.routerMap != nil {
if v, ok := r.routerMap[key]; ok {
2021-09-27 21:27:24 +08:00
return gvar.New(v)
}
2019-06-19 09:06:52 +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
}