github.com/gogf/gf@v1.16.9/net/ghttp/ghttp_request_param_router.go (about) 1 // Copyright GoFrame Author(https://goframe.org). 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/gogf/gf. 6 7 package ghttp 8 9 import "github.com/gogf/gf/container/gvar" 10 11 // GetRouterMap retrieves and returns a copy of router map. 12 func (r *Request) GetRouterMap() map[string]string { 13 if r.routerMap != nil { 14 m := make(map[string]string, len(r.routerMap)) 15 for k, v := range r.routerMap { 16 m[k] = v 17 } 18 return m 19 } 20 return nil 21 } 22 23 // GetRouterValue retrieves and returns the router value with given key name <key>. 24 // It returns <def> if <key> does not exist. 25 func (r *Request) GetRouterValue(key string, def ...interface{}) interface{} { 26 if r.routerMap != nil { 27 if v, ok := r.routerMap[key]; ok { 28 return v 29 } 30 } 31 if len(def) > 0 { 32 return def[0] 33 } 34 return nil 35 } 36 37 // GetRouterVar retrieves and returns the router value as gvar.Var with given key name <key>. 38 // It returns <def> if <key> does not exist. 39 func (r *Request) GetRouterVar(key string, def ...interface{}) *gvar.Var { 40 return gvar.New(r.GetRouterValue(key, def...)) 41 } 42 43 // GetRouterString retrieves and returns the router value as string with given key name <key>. 44 // It returns <def> if <key> does not exist. 45 func (r *Request) GetRouterString(key string, def ...interface{}) string { 46 return r.GetRouterVar(key, def...).String() 47 }