diff options
Diffstat (limited to 'internal/http/http.go')
| -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() |
