add remaining org/proj/user initial sync

This commit is contained in:
Mike Mason
2023-07-11 21:32:30 +00:00
parent 80fb879ef6
commit 11fe8f8f2a
15 changed files with 215 additions and 34 deletions

View File

@@ -0,0 +1,27 @@
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 ""
}