1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-09-15 18:57:04 +00:00

Consider base path when generating third-party services API endpoint

This commit is contained in:
Frédéric Guillot 2023-08-12 19:01:22 -07:00
parent fb8737e330
commit 13d9d86acd
9 changed files with 87 additions and 60 deletions

View file

@ -79,3 +79,26 @@ func Domain(websiteURL string) string {
return parsedURL.Host
}
// JoinBaseURLAndPath returns a URL string with the provided path elements joined together.
func JoinBaseURLAndPath(baseURL, path string) (string, error) {
if baseURL == "" {
return "", fmt.Errorf("empty base URL")
}
if path == "" {
return "", fmt.Errorf("empty path")
}
_, err := url.Parse(baseURL)
if err != nil {
return "", fmt.Errorf("invalid base URL: %w", err)
}
finalURL, err := url.JoinPath(baseURL, path)
if err != nil {
return "", fmt.Errorf("unable to join base URL %s and path %s: %w", baseURL, path, err)
}
return finalURL, nil
}