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