2017-10-02 18:37:36 +02:00
|
|
|
package rest
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/url"
|
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
// URLJoin joins a URL and a path returning a new URL
|
|
|
|
//
|
|
|
|
// path should be URL escaped
|
|
|
|
func URLJoin(base *url.URL, path string) (*url.URL, error) {
|
|
|
|
rel, err := url.Parse(path)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrapf(err, "Error parsing %q as URL", path)
|
|
|
|
}
|
|
|
|
return base.ResolveReference(rel), nil
|
|
|
|
}
|
|
|
|
|
2018-01-05 16:55:43 +01:00
|
|
|
// URLPathEscape escapes URL path the in string using URL escaping rules
|
2017-10-02 18:37:36 +02:00
|
|
|
//
|
|
|
|
// This mimics url.PathEscape which only available from go 1.8
|
2018-01-05 16:55:43 +01:00
|
|
|
func URLPathEscape(in string) string {
|
2017-10-02 18:37:36 +02:00
|
|
|
var u url.URL
|
|
|
|
u.Path = in
|
|
|
|
return u.String()
|
|
|
|
}
|