本文整理汇总了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")
}