diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2023-02-16 15:44:38 +0100 |
|---|---|---|
| committer | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2023-02-16 15:44:38 +0100 |
| commit | 2a46b5771d15ea55e20a5b52bddb6c04b55326e7 (patch) | |
| tree | 49d6bd70171bd0aa199d9f8f10e5dc4035344733 /internal | |
| parent | 75ac9ee246e7d3be5890b972a241855da875f4b0 (diff) | |
HTTP: Implement join URL path
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/http/http.go | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/internal/http/http.go b/internal/http/http.go index 73e7b13..c5939b5 100644 --- a/internal/http/http.go +++ b/internal/http/http.go @@ -59,6 +59,23 @@ func EnsureValidURL(s string) (string, error) { } return cleanPath(u), nil } + +// JoinURLPath joins url's path, in go 1.19 we can use url.JoinPath +func JoinURLPath(u string, p string) (string, error) { + pu, err := url.Parse(u) + if err != nil { + return "", errors.WrapPrefix(err, "failed to parse url for joining paths", 0) + } + pp, err := url.Parse(p) + if err != nil { + return "", errors.WrapPrefix(err, "failed to parse path for joining paths", 0) + } + fp := pu.ResolveReference(pp) + + // We also clean the path for consistency + return cleanPath(fp), nil +} + // ConstructURL creates a URL with the included parameters. func ConstructURL(u *url.URL, params URLParameters) (string, error) { q := u.Query() |
