Jon Perritt | 0e28b11 | 2014-10-14 20:49:31 -0500 | [diff] [blame] | 1 | package objects |
| 2 | |
| 3 | import ( |
| 4 | "io" |
| 5 | |
| 6 | "github.com/rackspace/gophercloud" |
| 7 | os "github.com/rackspace/gophercloud/openstack/objectstorage/v1/objects" |
| 8 | "github.com/rackspace/gophercloud/pagination" |
| 9 | ) |
| 10 | |
| 11 | // ExtractInfo is a function that takes a page of objects and returns their full information. |
| 12 | func ExtractInfo(page pagination.Page) ([]os.Object, error) { |
| 13 | return os.ExtractInfo(page) |
| 14 | } |
| 15 | |
| 16 | // ExtractNames is a function that takes a page of objects and returns only their names. |
| 17 | func ExtractNames(page pagination.Page) ([]string, error) { |
| 18 | return os.ExtractNames(page) |
| 19 | } |
| 20 | |
| 21 | // List is a function that retrieves objects in the container as |
| 22 | // well as container metadata. It returns a pager which can be iterated with the |
| 23 | // EachPage function. |
| 24 | func List(c *gophercloud.ServiceClient, containerName string, opts os.ListOptsBuilder) pagination.Pager { |
| 25 | return os.List(c, containerName, opts) |
| 26 | } |
| 27 | |
| 28 | // Download is a function that retrieves the content and metadata for an object. |
| 29 | // To extract just the content, pass the DownloadResult response to the |
| 30 | // ExtractContent function. |
| 31 | func Download(c *gophercloud.ServiceClient, containerName, objectName string, opts os.DownloadOptsBuilder) os.DownloadResult { |
| 32 | return os.Download(c, containerName, objectName, opts) |
| 33 | } |
| 34 | |
| 35 | // Create is a function that creates a new object or replaces an existing object. |
| 36 | func Create(c *gophercloud.ServiceClient, containerName, objectName string, content io.Reader, opts os.CreateOptsBuilder) os.CreateResult { |
| 37 | return os.Create(c, containerName, objectName, content, opts) |
| 38 | } |
| 39 | |
| 40 | // CopyOpts is a structure that holds parameters for copying one object to |
| 41 | // another. |
| 42 | type CopyOpts struct { |
| 43 | Metadata map[string]string |
| 44 | ContentDisposition string `h:"Content-Disposition"` |
| 45 | ContentEncoding string `h:"Content-Encoding"` |
| 46 | ContentLength int `h:"Content-Length"` |
| 47 | ContentType string `h:"Content-Type"` |
| 48 | CopyFrom string `h:"X-Copy_From"` |
| 49 | Destination string `h:"Destination"` |
| 50 | DetectContentType bool `h:"X-Detect-Content-Type"` |
| 51 | } |
| 52 | |
| 53 | // ToObjectCopyMap formats a CopyOpts into a map of headers. |
| 54 | func (opts CopyOpts) ToObjectCopyMap() (map[string]string, error) { |
| 55 | h, err := gophercloud.BuildHeaders(opts) |
| 56 | if err != nil { |
| 57 | return nil, err |
| 58 | } |
| 59 | for k, v := range opts.Metadata { |
| 60 | h["X-Object-Meta-"+k] = v |
| 61 | } |
| 62 | // `Content-Length` is required and a value of "0" is acceptable, but calling `gophercloud.BuildHeaders` |
| 63 | // will remove the `Content-Length` header if it's set to 0 (or equivalently not set). This will add |
| 64 | // the header if it's not already set. |
| 65 | if _, ok := h["Content-Length"]; !ok { |
| 66 | h["Content-Length"] = "0" |
| 67 | } |
| 68 | return h, nil |
| 69 | } |
| 70 | |
| 71 | // Copy is a function that copies one object to another. |
| 72 | func Copy(c *gophercloud.ServiceClient, containerName, objectName string, opts os.CopyOptsBuilder) os.CopyResult { |
| 73 | return os.Copy(c, containerName, objectName, opts) |
| 74 | } |
| 75 | |
| 76 | // Delete is a function that deletes an object. |
| 77 | func Delete(c *gophercloud.ServiceClient, containerName, objectName string, opts os.DeleteOptsBuilder) os.DeleteResult { |
| 78 | return os.Delete(c, containerName, objectName, opts) |
| 79 | } |
| 80 | |
| 81 | // Get is a function that retrieves the metadata of an object. To extract just the custom |
| 82 | // metadata, pass the GetResult response to the ExtractMetadata function. |
| 83 | func Get(c *gophercloud.ServiceClient, containerName, objectName string, opts os.GetOptsBuilder) os.GetResult { |
| 84 | return os.Get(c, containerName, objectName, opts) |
| 85 | } |
| 86 | |
| 87 | // Update is a function that creates, updates, or deletes an object's metadata. |
| 88 | func Update(c *gophercloud.ServiceClient, containerName, objectName string, opts os.UpdateOptsBuilder) os.UpdateResult { |
| 89 | return os.Update(c, containerName, objectName, opts) |
| 90 | } |
Jon Perritt | 9095760 | 2015-02-01 17:03:06 -0700 | [diff] [blame] | 91 | |
| 92 | func CreateTempURL(c *gophercloud.ServiceClient, containerName, objectName string, opts os.CreateTempURLOpts) (string, error) { |
| 93 | return os.CreateTempURL(c, containerName, objectName, opts) |
| 94 | } |