本文整理匯總了Golang中github.com/gorilla/mux.Route.Name方法的典型用法代碼示例。如果您正苦於以下問題:Golang Route.Name方法的具體用法?Golang Route.Name怎麽用?Golang Route.Name使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/gorilla/mux.Route
的用法示例。
在下文中一共展示了Route.Name方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: setItemRoutes
// Sets up all of the mux router routes for the items in the given resource
func (rm *ResourceManager) setItemRoutes(res Resource, itemOnly bool) {
var (
router *mux.Router
itemRoute *mux.Route
)
if itemOnly {
// If this resource has no "list", just use ResourceManager
// or parent item router
parent := res.ResourceParent()
router = rm.Router
if parent != nil {
// If this is a child resource, use it's parent item router as a sub router
router = rm.GetRoute(parent, "item").Subrouter()
}
itemRoute = router.PathPrefix(fmt.Sprintf("/%s/", res.ResourceName()))
} else {
// Else this has a list, so use the list router
router = rm.GetRoute(res, "list").Subrouter()
// In case of a list, use the regex specified for the id
idFormat := res.ResourceFullName()
if matcher, ok := res.(ResourceIdMatcher); ok {
// If there is a custom regex match for the ID on this resource,
// add that to the pathprefix for the URL
regex := matcher.ResourceIdMatcher()
if regex != "" {
idFormat = strings.Join([]string{idFormat, regex}, ":")
}
}
itemRoute = router.PathPrefix(fmt.Sprintf("/{%s}/", idFormat))
}
itemRoute = itemRoute.Name(res.ResourceFullName() + "." + "item")
rm.RegisterRoute(res, "item", itemRoute)
rm.setMethodRoutes(res, "Item")
}