You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
521 B
Go
29 lines
521 B
Go
package utils
|
|
|
|
import (
|
|
"net/url"
|
|
"regexp"
|
|
"strings"
|
|
)
|
|
|
|
// BaseEndpoint will return a URL without the /vX.Y
|
|
// portion of the URL.
|
|
func BaseEndpoint(endpoint string) (string, error) {
|
|
u, err := url.Parse(endpoint)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
u.RawQuery, u.Fragment = "", ""
|
|
|
|
path := u.Path
|
|
versionRe := regexp.MustCompile("v[0-9.]+/?")
|
|
|
|
if version := versionRe.FindString(path); version != "" {
|
|
versionIndex := strings.Index(path, version)
|
|
u.Path = path[:versionIndex]
|
|
}
|
|
|
|
return u.String(), nil
|
|
}
|