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:
parent
fb8737e330
commit
13d9d86acd
9 changed files with 87 additions and 60 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue