github.com/rclone/rclone@v1.66.1-0.20240517100346-7b89735ae726/lib/rest/url.go (about)

     1  package rest
     2  
     3  import (
     4  	"fmt"
     5  	"net/url"
     6  )
     7  
     8  // URLJoin joins a URL and a path returning a new URL
     9  //
    10  // path should be URL escaped
    11  func URLJoin(base *url.URL, path string) (*url.URL, error) {
    12  	rel, err := url.Parse(path)
    13  	if err != nil {
    14  		return nil, fmt.Errorf("error parsing %q as URL: %w", path, err)
    15  	}
    16  	return base.ResolveReference(rel), nil
    17  }
    18  
    19  // URLPathEscape escapes URL path the in string using URL escaping rules
    20  //
    21  // This mimics url.PathEscape which only available from go 1.8
    22  func URLPathEscape(in string) string {
    23  	var u url.URL
    24  	u.Path = in
    25  	return u.String()
    26  }