本文整理汇总了Golang中github.com/gorilla/mux.Route.URL方法的典型用法代码示例。如果您正苦于以下问题:Golang Route.URL方法的具体用法?Golang Route.URL怎么用?Golang Route.URL使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/gorilla/mux.Route
的用法示例。
在下文中一共展示了Route.URL方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: webify
func webify(result map[string]string, resource string) map[string]string {
result["resource"] = resource
icon := result["icon"]
if icon == "" || strings.HasPrefix(icon, "http") {
return result
}
result["icon"] = ""
var route *mux.Route
var args []string
if strings.HasPrefix(icon, dirs.SnapIconsDir) {
route = metaIconCmd.d.router.Get(metaIconCmd.Path)
args = []string{"icon", icon[len(dirs.SnapIconsDir)+1:]}
} else {
route = appIconCmd.d.router.Get(appIconCmd.Path)
args = []string{"name", result["name"], "origin", result["origin"]}
}
if route != nil {
url, err := route.URL(args...)
if err == nil {
result["icon"] = url.String()
}
}
return result
}
示例2: Location
// Location of the task, based on the given route.
//
// If the route can't build a URL for this task, returns the empty
// string.
func (t *Task) Location(route *mux.Route) string {
url, err := route.URL("uuid", t.id.String())
if err != nil {
return ""
}
return url.String()
}
示例3: URL
func (u *urlBuilder) URL(out *string, route string) *urlBuilder {
var r *mux.Route
var url *url.URL
if u.Error == nil {
r = u.Route(route)
}
if u.Error == nil {
url, u.Error = r.URL(u.Params...)
}
if u.Error == nil {
*out = url.String()
}
return u
}
示例4: Template
func (u *urlBuilder) Template(out *string, route, param string) *urlBuilder {
var r *mux.Route
var url *url.URL
if u.Error == nil {
r = u.Route(route)
}
if u.Error == nil {
params := append([]string{param, "---"}, u.Params...)
url, u.Error = r.URL(params...)
}
if u.Error == nil {
*out = strings.Replace(url.String(), "---", "{"+param+"}", 1)
}
return u
}
示例5: sendStorePackages
func sendStorePackages(route *mux.Route, meta *Meta, found []*snap.Info) Response {
results := make([]*json.RawMessage, 0, len(found))
for _, x := range found {
url, err := route.URL("name", x.Name())
if err != nil {
logger.Noticef("Cannot build URL for snap %q revision %s: %v", x.Name(), x.Revision, err)
continue
}
data, err := json.Marshal(webify(mapRemote(x), url.String()))
if err != nil {
return InternalError("%v", err)
}
raw := json.RawMessage(data)
results = append(results, &raw)
}
return SyncResponse(results, meta)
}
示例6: PrintRoutes
// PrintRoutes Attempts to print all register routes when called using mux.Router.Walk(PrintRoutes)
func PrintRoutes(route *mux.Route, router *mux.Router, ancestors []*mux.Route) error {
url, _ := route.URL()
fmt.Println(route.GetName(), url)
return nil
}