diff options
| author | Stefan Majewsky <majewsky@gmx.net> | 2018-02-05 21:30:33 +0100 |
|---|---|---|
| committer | Stefan Majewsky <majewsky@gmx.net> | 2018-02-05 21:44:35 +0100 |
| commit | 3a24741929cd12ffee5e54d0e9a9afb83c5069b3 (patch) | |
| tree | 6a91b159d25814e873fcfae08cd40cba9b1dcc14 /container.go | |
| parent | 7de32502590995ee8d7cc8b681b0f723ca35ccb0 (diff) | |
| download | go-schwift-3a24741929cd12ffee5e54d0e9a9afb83c5069b3.tar.gz | |
redesign the header API
I'm quite satisfied with this right now (though this doesn't say
anything about how I feel about it tomorrow), but it's ugly that some
guts (headers.Base) are exposed in the public API.
Diffstat (limited to 'container.go')
| -rw-r--r-- | container.go | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/container.go b/container.go index 9fcfe2b..e3b95d8 100644 --- a/container.go +++ b/container.go @@ -79,17 +79,18 @@ func (c *Container) Headers() (ContainerHeaders, error) { return ContainerHeaders{}, err } - var headers ContainerHeaders - err = parseHeaders(resp.Header, &headers) + headers := NewContainerHeaders() + headers.FromHTTP(resp.Header) + err = headers.Validate() if err != nil { - return ContainerHeaders{}, err + return headers, err } c.headers = &headers return *c.headers, nil } -//Update updates the container using a POST request. To set arbitrary request -//headers (and to add URL parameters), pass a non-nil *RequestOptions. +//Update updates the container using a POST request. To add URL parameters, pass +//a non-nil *RequestOptions. // //If you are not sure whether the container exists, use Create() instead. // @@ -98,7 +99,8 @@ func (c *Container) Update(headers ContainerHeaders, opts *RequestOptions) error _, err := Request{ Method: "POST", ContainerName: c.name, - Options: compileHeaders(&headers, opts), + Headers: headers.ToHTTP(), + Options: opts, ExpectStatusCodes: []int{204}, }.Do(c.a.client) if err == nil { @@ -107,8 +109,8 @@ func (c *Container) Update(headers ContainerHeaders, opts *RequestOptions) error return err } -//Create creates the container using a PUT request. To set arbitrary request -//headers (and to add URL parameters), pass a non-nil *RequestOptions. +//Create creates the container using a PUT request. To add URL parameters, pass +//a non-nil *RequestOptions. // //This function can be used regardless of whether the container exists or not. // @@ -117,7 +119,8 @@ func (c *Container) Create(headers ContainerHeaders, opts *RequestOptions) error _, err := Request{ Method: "PUT", ContainerName: c.name, - Options: compileHeaders(&headers, opts), + Headers: headers.ToHTTP(), + Options: opts, ExpectStatusCodes: []int{201, 202}, }.Do(c.a.client) if err == nil { @@ -126,8 +129,8 @@ func (c *Container) Create(headers ContainerHeaders, opts *RequestOptions) error return err } -//Delete deletes the container using a DELETE request. To set arbitrary request -//headers (and to add URL parameters), pass a non-nil *RequestOptions. +//Delete deletes the container using a DELETE request. To add URL parameters, +//pass a non-nil *RequestOptions. // //This operation fails with http.StatusConflict if the container is not empty. // @@ -138,7 +141,8 @@ func (c *Container) Delete(headers ContainerHeaders, opts *RequestOptions) error _, err := Request{ Method: "DELETE", ContainerName: c.name, - Options: compileHeaders(&headers, opts), + Headers: headers.ToHTTP(), + Options: opts, ExpectStatusCodes: []int{204}, }.Do(c.a.client) if err == nil { |
