Jon Perritt | 0e28b11 | 2014-10-14 20:49:31 -0500 | [diff] [blame^] | 1 | package containers |
| 2 | |
| 3 | import ( |
| 4 | "github.com/rackspace/gophercloud" |
| 5 | os "github.com/rackspace/gophercloud/openstack/objectstorage/v1/containers" |
| 6 | "github.com/rackspace/gophercloud/pagination" |
| 7 | ) |
| 8 | |
| 9 | // List is a function that retrieves containers associated with the account as |
| 10 | // well as account metadata. It returns a pager which can be iterated with the |
| 11 | // EachPage function. |
| 12 | func List(c *gophercloud.ServiceClient, opts *os.ListOpts) pagination.Pager { |
| 13 | return os.List(c, opts) |
| 14 | } |
| 15 | |
| 16 | // CreateOpts is a structure that holds parameters for creating a container. |
| 17 | type CreateOpts struct { |
| 18 | Metadata map[string]string |
| 19 | ContainerRead string `h:"X-Container-Read"` |
| 20 | ContainerWrite string `h:"X-Container-Write"` |
| 21 | VersionsLocation string `h:"X-Versions-Location"` |
| 22 | } |
| 23 | |
| 24 | // ToContainerCreateMap formats a CreateOpts into a map of headers. |
| 25 | func (opts CreateOpts) ToContainerCreateMap() (map[string]string, error) { |
| 26 | h, err := gophercloud.BuildHeaders(opts) |
| 27 | if err != nil { |
| 28 | return nil, err |
| 29 | } |
| 30 | for k, v := range opts.Metadata { |
| 31 | h["X-Container-Meta-"+k] = v |
| 32 | } |
| 33 | return h, nil |
| 34 | } |
| 35 | |
| 36 | // Create is a function that creates a new container. |
| 37 | func Create(c *gophercloud.ServiceClient, containerName string, opts os.CreateOptsBuilder) os.CreateResult { |
| 38 | return os.Create(c, containerName, opts) |
| 39 | } |
| 40 | |
| 41 | // Delete is a function that deletes a container. |
| 42 | func Delete(c *gophercloud.ServiceClient, containerName string) os.DeleteResult { |
| 43 | return os.Delete(c, containerName) |
| 44 | } |
| 45 | |
| 46 | // UpdateOpts is a structure that holds parameters for updating or creating a |
| 47 | // container's metadata. |
| 48 | type UpdateOpts struct { |
| 49 | Metadata map[string]string |
| 50 | ContainerRead string `h:"X-Container-Read"` |
| 51 | ContainerWrite string `h:"X-Container-Write"` |
| 52 | ContentType string `h:"Content-Type"` |
| 53 | DetectContentType bool `h:"X-Detect-Content-Type"` |
| 54 | RemoveVersionsLocation string `h:"X-Remove-Versions-Location"` |
| 55 | VersionsLocation string `h:"X-Versions-Location"` |
| 56 | } |
| 57 | |
| 58 | // ToContainerUpdateMap formats a CreateOpts into a map of headers. |
| 59 | func (opts UpdateOpts) ToContainerUpdateMap() (map[string]string, error) { |
| 60 | h, err := gophercloud.BuildHeaders(opts) |
| 61 | if err != nil { |
| 62 | return nil, err |
| 63 | } |
| 64 | for k, v := range opts.Metadata { |
| 65 | h["X-Container-Meta-"+k] = v |
| 66 | } |
| 67 | return h, nil |
| 68 | } |
| 69 | |
| 70 | // Update is a function that creates, updates, or deletes a container's |
| 71 | // metadata. |
| 72 | func Update(c *gophercloud.ServiceClient, containerName string, opts *os.UpdateOpts) os.UpdateResult { |
| 73 | return os.Update(c, containerName, opts) |
| 74 | } |
| 75 | |
| 76 | // Get is a function that retrieves the metadata of a container. To extract just |
| 77 | // the custom metadata, pass the GetResult response to the ExtractMetadata |
| 78 | // function. |
| 79 | func Get(c *gophercloud.ServiceClient, containerName string) os.GetResult { |
| 80 | return os.Get(c, containerName) |
| 81 | } |