Exemplo n.º 1
0
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
}
Exemplo n.º 2
0
// 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()
}
Exemplo n.º 3
0
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
}
Exemplo n.º 4
0
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
}
Exemplo n.º 5
0
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)
}
Exemplo n.º 6
0
// 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
}