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 /container.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 'container.go')
| -rw-r--r-- | container.go | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/container.go b/container.go index 741350e..1d310aa 100644 --- a/container.go +++ b/container.go @@ -36,7 +36,7 @@ type Container struct { //container's existence, or chain this function with the EnsureExists() //function like so: // -// container, err := account.Container("documents").EnsureExists() +// container, err := account.Container("documents").EnsureExists() func (a *Account) Container(name string) *Container { return &Container{a: a, name: name} } @@ -81,7 +81,7 @@ func (c *Container) Headers() (ContainerHeaders, error) { return ContainerHeaders{}, err } - headers := ContainerHeaders(headersFromHTTP(resp.Header)) + headers := ContainerHeaders{headersFromHTTP(resp.Header)} err = headers.Validate() if err != nil { return headers, err @@ -100,8 +100,7 @@ func (c *Container) Update(headers ContainerHeaders, opts *RequestOptions) error _, err := Request{ Method: "POST", ContainerName: c.name, - Headers: headersToHTTP(headers), - Options: opts, + Options: cloneRequestOptions(opts, headers.Headers), ExpectStatusCodes: []int{204}, }.Do(c.a.backend) if err == nil { @@ -116,11 +115,10 @@ func (c *Container) Update(headers ContainerHeaders, opts *RequestOptions) error //This function can be used regardless of whether the container exists or not. // //A successful PUT request implies Invalidate() since it may change metadata. -func (c *Container) Create(headers ContainerHeaders, opts *RequestOptions) error { +func (c *Container) Create(opts *RequestOptions) error { _, err := Request{ Method: "PUT", ContainerName: c.name, - Headers: headersToHTTP(headers), Options: opts, ExpectStatusCodes: []int{201, 202}, DrainResponseBody: true, @@ -139,11 +137,10 @@ func (c *Container) Create(headers ContainerHeaders, opts *RequestOptions) error //This operation fails with http.StatusNotFound if the container does not exist. // //A successful DELETE request implies Invalidate(). -func (c *Container) Delete(headers ContainerHeaders, opts *RequestOptions) error { +func (c *Container) Delete(opts *RequestOptions) error { _, err := Request{ Method: "DELETE", ContainerName: c.name, - Headers: headersToHTTP(headers), Options: opts, ExpectStatusCodes: []int{204}, }.Do(c.a.backend) @@ -165,7 +162,7 @@ func (c *Container) Invalidate() { //This function returns the same container again, because its intended use is //with freshly constructed Container instances like so: // -// container, err := account.Container("documents").EnsureExists() +// container, err := account.Container("documents").EnsureExists() func (c *Container) EnsureExists() (*Container, error) { _, err := Request{ Method: "PUT", |
