metadata/resource.go
func (r *Resource) ExtractVariables(href string) ([]*PathVariable, error) {
	matches := r.findMatches(href)
	if len(matches) == 0 && !strings.HasPrefix(href, "/") {
		href = "/" + href
		matches = r.findMatches(href)
	}
	if len(matches) == 0 {
		return nil, fmt.Errorf("Href '%s' does not match any action path of resource %s", href, r.Name)
	}
	sort.Sort(ByLen(matches))
	pattern := matches[0]
	submatches := pattern.Regexp.FindAllStringSubmatch(href, -1)
	if len(submatches) == 0 {
		return []*PathVariable{}, nil
	}
	if len(submatches) > 1 {
		// Not right... there should only be one
		return nil, fmt.Errorf("Ambiguous href '%s', matches multiple path patterns of %s actions",
			href, r.Name)
	}
	submatch := submatches[0]
	variables := make([]*PathVariable, len(submatch)-1)
	for i, v := range submatch[1:] {
		variables[i] = &PathVariable{Name: pattern.Variables[i], Value: v}

	}
	return variables, nil
}
func (r *Resource) ExtractVariables(href string) ([]*PathVariable, error) {
	matches := r.findMatches(href)
	if len(matches) == 0 && !strings.HasPrefix(href, "/") {
		href = "/" + href
		matches = r.findMatches(href)
	}
	if len(matches) == 0 {
		return nil, fmt.Errorf("Href '%s' does not match any action path of resource %s", href, r.Name)
	}
	sort.Sort(ByLen(matches))
	pattern := matches[0]
	submatches := pattern.Regexp.FindAllStringSubmatch(href, -1)
	if len(submatches) == 0 {
		return []*PathVariable{}, nil
	}
	if len(submatches) > 1 {
		// Not right... there should only be one
		return nil, fmt.Errorf("Ambiguous href '%s', matches multiple path patterns of %s actions",
			href, r.Name)
	}
	submatch := submatches[0]
	variables := make([]*PathVariable, len(submatch)-1)
	for i, v := range submatch[1:] {
		variables[i] = &PathVariable{Name: pattern.Variables[i], Value: v}

	}
	return variables, nil
}
// ExtractVariables takes a resource href and extracts the variables (cloud_id, id etc.) that
// make it up. It does that by matching the href against all the resource action path patterns
// and finding the longest one that matches.