From 088806ba4c7fbd6e540e77857fb9fb7dac40fda2 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Thu, 6 Jul 2017 12:12:01 +0100 Subject: [PATCH] rest: add Parameters field to opts for adding URL parameters --- rest/rest.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/rest/rest.go b/rest/rest.go index 7f8fedae8..9ac1fd9d7 100644 --- a/rest/rest.go +++ b/rest/rest.go @@ -10,6 +10,7 @@ import ( "io/ioutil" "mime/multipart" "net/http" + "net/url" "sync" "github.com/ncw/rclone/fs" @@ -90,10 +91,11 @@ type Opts struct { UserName string // username for Basic Auth Password string // password for Basic Auth Options []fs.OpenOption - IgnoreStatus bool // if set then we don't check error status or parse error body - MultipartMetadataName string // set the following 3 vars - MultipartContentName string // and Body and pass in request - MultipartFileName string // for multipart upload + IgnoreStatus bool // if set then we don't check error status or parse error body + MultipartMetadataName string // set the following 3 vars + MultipartContentName string // and Body and pass in request + MultipartFileName string // for multipart upload + Parameters url.Values // any parameters for the final URL } // Copy creates a copy of the options @@ -153,6 +155,9 @@ func (api *Client) Call(opts *Opts) (resp *http.Response, err error) { } url = api.rootURL + opts.Path } + if opts.Parameters != nil && len(opts.Parameters) > 0 { + url += "?" + opts.Parameters.Encode() + } req, err := http.NewRequest(opts.Method, url, opts.Body) if err != nil { return