diff options
| author | Sandro Jäckel <sandro.jaeckel@sap.com> | 2022-10-26 11:31:22 +0200 |
|---|---|---|
| committer | Sandro Jäckel <sandro.jaeckel@sap.com> | 2022-10-26 14:05:42 +0200 |
| commit | 04ce17415f25dbf10eba954212c8428ae630df88 (patch) | |
| tree | 1aca7ceab052f17a44bb903fb5a8bd45202bd54c /container.go | |
| parent | fd6e57b6239655722884a49a86be0f051cc32bde (diff) | |
| download | go-schwift-04ce17415f25dbf10eba954212c8428ae630df88.tar.gz | |
Format with go 1.19
Diffstat (limited to 'container.go')
| -rw-r--r-- | container.go | 95 |
1 files changed, 47 insertions, 48 deletions
diff --git a/container.go b/container.go index de85f62..476a704 100644 --- a/container.go +++ b/container.go @@ -22,9 +22,9 @@ import ( "net/http" ) -//Container represents a Swift container. Instances are usually obtained by -//traversing downwards from an account with Account.Container() or -//Account.Containers(), or upwards from an object with Object.Container(). +// Container represents a Swift container. Instances are usually obtained by +// traversing downwards from an account with Account.Container() or +// Account.Containers(), or upwards from an object with Object.Container(). type Container struct { a *Account name string @@ -32,34 +32,34 @@ type Container struct { headers *ContainerHeaders } -//IsEqualTo returns true if both Container instances refer to the same container. +// IsEqualTo returns true if both Container instances refer to the same container. func (c *Container) IsEqualTo(other *Container) bool { return other.name == c.name && other.a.IsEqualTo(c.a) } -//Container returns a handle to the container with the given name within this -//account. This function does not issue any HTTP requests, and therefore cannot -//ensure that the container exists. Use the Exists() function to check for the -//container's existence, or chain this function with the EnsureExists() -//function like so: +// Container returns a handle to the container with the given name within this +// account. This function does not issue any HTTP requests, and therefore cannot +// ensure that the container exists. Use the Exists() function to check for the +// container's existence, or chain this function with the EnsureExists() +// function like so: // // container, err := account.Container("documents").EnsureExists() func (a *Account) Container(name string) *Container { return &Container{a: a, name: name} } -//Account returns a handle to the account this container is stored in. +// Account returns a handle to the account this container is stored in. func (c *Container) Account() *Account { return c.a } -//Name returns the container name. +// Name returns the container name. func (c *Container) Name() string { return c.name } -//Exists checks if this container exists, potentially by issuing a HEAD request -//if no Headers() have been cached yet. +// Exists checks if this container exists, potentially by issuing a HEAD request +// if no Headers() have been cached yet. func (c *Container) Exists() (bool, error) { _, err := c.Headers() if Is(err, http.StatusNotFound) { @@ -70,13 +70,13 @@ func (c *Container) Exists() (bool, error) { return true, nil } -//Headers returns the ContainerHeaders for this container. If the ContainerHeaders -//has not been cached yet, a HEAD request is issued on the container. +// Headers returns the ContainerHeaders for this container. If the ContainerHeaders +// has not been cached yet, a HEAD request is issued on the container. // -//This operation fails with http.StatusNotFound if the container does not exist. +// This operation fails with http.StatusNotFound if the container does not exist. // -//WARNING: This method is not thread-safe. Calling it concurrently on the same -//object results in undefined behavior. +// WARNING: This method is not thread-safe. Calling it concurrently on the same +// object results in undefined behavior. func (c *Container) Headers() (ContainerHeaders, error) { if c.headers != nil { return *c.headers, nil @@ -100,12 +100,12 @@ func (c *Container) Headers() (ContainerHeaders, error) { return *c.headers, nil } -//Update updates the container using a POST request. 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. +// If you are not sure whether the container exists, use Create() instead. // -//A successful POST request implies Invalidate() since it may change metadata. +// A successful POST request implies Invalidate() since it may change metadata. func (c *Container) Update(headers ContainerHeaders, opts *RequestOptions) error { _, err := Request{ Method: "POST", @@ -119,12 +119,12 @@ func (c *Container) Update(headers ContainerHeaders, opts *RequestOptions) error return err } -//Create creates the container using a PUT request. 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. +// This function can be used regardless of whether the container exists or not. // -//A successful PUT request implies Invalidate() since it may change metadata. +// A successful PUT request implies Invalidate() since it may change metadata. func (c *Container) Create(opts *RequestOptions) error { _, err := Request{ Method: "PUT", @@ -139,14 +139,14 @@ func (c *Container) Create(opts *RequestOptions) error { return err } -//Delete deletes the container using a DELETE request. 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. +// This operation fails with http.StatusConflict if the container is not empty. // -//This operation fails with http.StatusNotFound if the container does not exist. +// This operation fails with http.StatusNotFound if the container does not exist. // -//A successful DELETE request implies Invalidate(). +// A successful DELETE request implies Invalidate(). func (c *Container) Delete(opts *RequestOptions) error { _, err := Request{ Method: "DELETE", @@ -160,20 +160,20 @@ func (c *Container) Delete(opts *RequestOptions) error { return err } -//Invalidate clears the internal cache of this Container instance. The next call -//to Headers() on this instance will issue a HEAD request on the container. +// Invalidate clears the internal cache of this Container instance. The next call +// to Headers() on this instance will issue a HEAD request on the container. // -//WARNING: This method is not thread-safe. Calling it concurrently on the same -//object results in undefined behavior. +// WARNING: This method is not thread-safe. Calling it concurrently on the same +// object results in undefined behavior. func (c *Container) Invalidate() { c.headers = nil } -//EnsureExists issues a PUT request on this container. -//If the container does not exist yet, it will be created by this call. -//If the container exists already, this call does not change it. -//This function returns the same container again, because its intended use is -//with freshly constructed Container instances like so: +// EnsureExists issues a PUT request on this container. +// If the container does not exist yet, it will be created by this call. +// If the container exists already, this call does not change it. +// 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() func (c *Container) EnsureExists() (*Container, error) { @@ -186,31 +186,30 @@ func (c *Container) EnsureExists() (*Container, error) { return c, err } -//Objects returns an ObjectIterator that lists the objects in this -//container. The most common use case is: +// Objects returns an ObjectIterator that lists the objects in this +// container. The most common use case is: // // objects, err := container.Objects().Collect() // -//You can extend this by configuring the iterator before collecting the results: +// You can extend this by configuring the iterator before collecting the results: // // iter := container.Objects() // iter.Prefix = "test-" // objects, err := iter.Collect() // -//Or you can use a different iteration method: +// Or you can use a different iteration method: // // err := container.Objects().ForeachDetailed(func (info ObjectInfo) error { // log.Printf("object %s is %d bytes large!\n", // info.Object.Name(), info.SizeBytes) // }) -// func (c *Container) Objects() *ObjectIterator { return &ObjectIterator{Container: c} } -//URL returns the canonical URL for this container on the server. This is -//particularly useful when the ReadACL on the account or container is set to -//allow anonymous read access. +// URL returns the canonical URL for this container on the server. This is +// particularly useful when the ReadACL on the account or container is set to +// allow anonymous read access. func (c *Container) URL() (string, error) { return Request{ ContainerName: c.name, |
