forked from TrueCloudLab/rclone
rest: Allow RootURL to be overridden
This commit is contained in:
parent
088806ba4c
commit
5f70746d39
1 changed files with 10 additions and 5 deletions
15
rest/rest.go
15
rest/rest.go
|
@ -79,9 +79,10 @@ func (api *Client) SetHeader(key, value string) *Client {
|
||||||
|
|
||||||
// Opts contains parameters for Call, CallJSON etc
|
// Opts contains parameters for Call, CallJSON etc
|
||||||
type Opts struct {
|
type Opts struct {
|
||||||
Method string
|
Method string // GET, POST etc
|
||||||
Path string
|
Path string // relative to RootURL unless Absolute set
|
||||||
Absolute bool // Path is absolute
|
Absolute bool // Path is absolute - dont add RootURL
|
||||||
|
RootURL string // override RootURL passed into SetRoot()
|
||||||
Body io.Reader
|
Body io.Reader
|
||||||
NoResponse bool // set to close Body
|
NoResponse bool // set to close Body
|
||||||
ContentType string
|
ContentType string
|
||||||
|
@ -150,10 +151,14 @@ func (api *Client) Call(opts *Opts) (resp *http.Response, err error) {
|
||||||
if opts.Absolute {
|
if opts.Absolute {
|
||||||
url = opts.Path
|
url = opts.Path
|
||||||
} else {
|
} else {
|
||||||
if api.rootURL == "" {
|
url = api.rootURL
|
||||||
|
if opts.RootURL != "" {
|
||||||
|
url = opts.RootURL
|
||||||
|
}
|
||||||
|
if url == "" {
|
||||||
return nil, errors.New("RootURL not set")
|
return nil, errors.New("RootURL not set")
|
||||||
}
|
}
|
||||||
url = api.rootURL + opts.Path
|
url += opts.Path
|
||||||
}
|
}
|
||||||
if opts.Parameters != nil && len(opts.Parameters) > 0 {
|
if opts.Parameters != nil && len(opts.Parameters) > 0 {
|
||||||
url += "?" + opts.Parameters.Encode()
|
url += "?" + opts.Parameters.Encode()
|
||||||
|
|
Loading…
Add table
Reference in a new issue