add remaining org/proj/user initial sync
This commit is contained in:
27
internal/metal/providers/emapi/helpers.go
Normal file
27
internal/metal/providers/emapi/helpers.go
Normal 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 ""
|
||||
}
|
||||
Reference in New Issue
Block a user