github.com/wangyougui/gf/v2@v2.6.5/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/wangyougui/gf.
     6  
     7  package ghttp
     8  
     9  import "github.com/wangyougui/gf/v2/container/gvar"
    10  
    11  // GetRouterMap retrieves and returns a copy of the 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  // GetRouter retrieves and returns the router value with given key name `key`.
    24  // It returns `def` if `key` does not exist.
    25  func (r *Request) GetRouter(key string, def ...interface{}) *gvar.Var {
    26  	if r.routerMap != nil {
    27  		if v, ok := r.routerMap[key]; ok {
    28  			return gvar.New(v)
    29  		}
    30  	}
    31  	if len(def) > 0 {
    32  		return gvar.New(def[0])
    33  	}
    34  	return nil
    35  }