package emapi import ( "net/url" "strings" ) // idOrLinkID returns the id if not empty, otherwise it plucks the last subpath from the link. // An empty string is returned if nothing is defined or an error occurs. func idOrLinkID(id, link string) string { if id != "" || link == "" { return id } url, err := url.Parse(link) if err != nil { return "" } parts := strings.Split(strings.TrimRight(url.Path, "/"), "/") if len(parts) != 0 { return parts[len(parts)-1] } return "" }