diff options
| author | Stefan Majewsky <majewsky@gmx.net> | 2018-03-11 19:38:27 +0100 |
|---|---|---|
| committer | Stefan Majewsky <majewsky@gmx.net> | 2018-03-11 19:41:33 +0100 |
| commit | d23b4052c0866698b14ac13ac98581d9f5440a9b (patch) | |
| tree | 51c93559594f8fd5136fd51b7397a30415ea93aa /account.go | |
| parent | aaf61ac55e18a04fd68b9b6ee4fd4fce49659eeb (diff) | |
| download | go-schwift-d23b4052c0866698b14ac13ac98581d9f5440a9b.tar.gz | |
revamp the Headers API
1. Move common methods of AccountHeaders, ContainerHeaders,
ObjectHeaders into a base type Headers.
2. Fold Headers into RequestOptions to remove one of the two optional
arguments on request methods. The new Headers.ToOpts() method
offers a nice experience for users passing Headers to request
methods.
The Update() methods keep the explicit Headers argument since the
Headers argument is not optional there.
The only downside is that we lose a bit of type-safety because
RequestOptions takes any Headers instance, so e.g. ContainerHeaders
could be passed to Object.Upload(). I believe the benefits outweigh
this problem.
Diffstat (limited to 'account.go')
| -rw-r--r-- | account.go | 19 |
1 files changed, 7 insertions, 12 deletions
@@ -98,7 +98,7 @@ func (a *Account) Headers() (AccountHeaders, error) { return AccountHeaders{}, err } - headers := AccountHeaders(headersFromHTTP(resp.Header)) + headers := AccountHeaders{headersFromHTTP(resp.Header)} err = headers.Validate() if err != nil { return headers, err @@ -113,15 +113,14 @@ func (a *Account) Invalidate() { a.headers = nil } -//Update updates the account using a POST request. To add URL parameters, pass -//a non-nil *RequestOptions. +//Update updates the account using a POST request. The headers in the headers +//attribute take precedence over those in opts.Headers. // //A successful POST request implies Invalidate() since it may change metadata. func (a *Account) Update(headers AccountHeaders, opts *RequestOptions) error { _, err := Request{ Method: "POST", - Headers: headersToHTTP(headers), - Options: opts, + Options: cloneRequestOptions(opts, headers.Headers), ExpectStatusCodes: []int{204}, }.Do(a.backend) if err == nil { @@ -130,17 +129,13 @@ func (a *Account) Update(headers AccountHeaders, opts *RequestOptions) error { return err } -//Create creates the account using a PUT request. To add URL parameters, pass -//a non-nil *RequestOptions. -// -//Note that this operation is only available to reseller admins, not to regular -//users. +//Create creates the account using a PUT request. This operation is only +//available to reseller admins, not to regular users. // //A successful PUT request implies Invalidate() since it may change metadata. -func (a *Account) Create(headers AccountHeaders, opts *RequestOptions) error { +func (a *Account) Create(opts *RequestOptions) error { _, err := Request{ Method: "PUT", - Headers: headersToHTTP(headers), Options: opts, ExpectStatusCodes: []int{201, 202}, DrainResponseBody: true, |
