"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files
Go azure-blobazure-blob-storageazure-filesbackblaze-b2cloud-storagedropboxencryptionftpfuse-filesystemgogolanggoogle-cloud-storagegoogle-driveonedriveopenstack-swiftrclones3sftpsyncwebdav
rest: add a Signer callback
Nick Craig-Wood2453abfbea6a
diff --git a/rest/rest.go b/rest/rest.goindex 0668540e7..812777234 100644--- a/rest/rest.go+++ b/rest/rest.go@@ -25,6 +25,7 @@ type Client struct {rootURL stringerrorHandler func(resp *http.Response) errorheaders map[string]string+ signer SignerFn}// NewClient takes an oauth http.Client and makes a new api instance@@ -79,6 +80,17 @@ func (api *Client) SetHeader(key, value string) *Client {return api}+// SignerFn is used to sign an outgoing request+type SignerFn func(*http.Request) error++// SetSigner sets a signer for all requests+func (api *Client) SetSigner(signer SignerFn) *Client {+ api.mu.Lock()+ defer api.mu.Unlock()+ api.signer = signer+ return api+}+// Opts contains parameters for Call, CallJSON etctype Opts struct {Method string // GET, POST etc@@ -211,6 +223,12 @@ func (api *Client) Call(opts *Opts) (resp *http.Response, err error) {req.SetBasicAuth(opts.UserName, opts.Password)}c := ClientWithHeaderReset(api.c, headers)+ if api.signer != nil {+ err = api.signer(req)+ if err != nil {+ return nil, errors.Wrap(err, "signer failed")+ }+ }api.mu.RUnlock()resp, err = c.Do(req)api.mu.RLock()