Jon Perritt | 816d2a0 | 2014-03-11 20:49:46 -0500 | [diff] [blame] | 1 | package objects |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
Jon Perritt | 8c93a30 | 2014-09-28 22:35:57 -0500 | [diff] [blame] | 5 | "io" |
| 6 | "time" |
Ash Wilson | 604320e | 2014-09-10 16:02:28 -0400 | [diff] [blame] | 7 | |
| 8 | "github.com/racker/perigee" |
| 9 | "github.com/rackspace/gophercloud" |
Ash Wilson | ca6f756 | 2014-09-16 15:43:54 -0400 | [diff] [blame] | 10 | "github.com/rackspace/gophercloud/pagination" |
Jon Perritt | 816d2a0 | 2014-03-11 20:49:46 -0500 | [diff] [blame] | 11 | ) |
| 12 | |
Jon Perritt | 8c93a30 | 2014-09-28 22:35:57 -0500 | [diff] [blame] | 13 | // ListOpts is a structure that holds parameters for listing objects. |
| 14 | type ListOpts struct { |
| 15 | Full bool |
| 16 | Limit int `q:"limit"` |
| 17 | Marker string `q:"marker"` |
| 18 | EndMarker string `q:"end_marker"` |
| 19 | Format string `q:"format"` |
| 20 | Prefix string `q:"prefix"` |
| 21 | Delimiter [1]byte `q:"delimiter"` |
| 22 | Path string `q:"path"` |
Ash Wilson | ca6f756 | 2014-09-16 15:43:54 -0400 | [diff] [blame] | 23 | } |
| 24 | |
Jon Perritt | 816d2a0 | 2014-03-11 20:49:46 -0500 | [diff] [blame] | 25 | // List is a function that retrieves all objects in a container. It also returns the details |
| 26 | // for the container. To extract only the object information or names, pass the ListResult |
Jon Perritt | eb57564 | 2014-04-24 15:16:31 -0500 | [diff] [blame] | 27 | // response to the ExtractInfo or ExtractNames function, respectively. |
Jon Perritt | de47eac | 2014-09-30 15:34:17 -0500 | [diff] [blame] | 28 | func List(c *gophercloud.ServiceClient, containerName string, opts *ListOpts) pagination.Pager { |
Ash Wilson | ca6f756 | 2014-09-16 15:43:54 -0400 | [diff] [blame] | 29 | var headers map[string]string |
Jon Perritt | 816d2a0 | 2014-03-11 20:49:46 -0500 | [diff] [blame] | 30 | |
Jon Perritt | de47eac | 2014-09-30 15:34:17 -0500 | [diff] [blame] | 31 | url := containerURL(c, containerName) |
| 32 | if opts != nil { |
| 33 | query, err := gophercloud.BuildQueryString(opts) |
| 34 | if err != nil { |
| 35 | fmt.Printf("Error building query string: %v", err) |
| 36 | return pagination.Pager{Err: err} |
| 37 | } |
| 38 | url += query.String() |
Jon Perritt | 816d2a0 | 2014-03-11 20:49:46 -0500 | [diff] [blame] | 39 | |
Jon Perritt | de47eac | 2014-09-30 15:34:17 -0500 | [diff] [blame] | 40 | if !opts.Full { |
| 41 | headers = map[string]string{"Accept": "text/plain", "Content-Type": "text/plain"} |
| 42 | } |
Jon Perritt | 5db0892 | 2014-09-30 21:32:48 -0500 | [diff] [blame] | 43 | } else { |
| 44 | headers = map[string]string{"Accept": "text/plain", "Content-Type": "text/plain"} |
Ash Wilson | ca6f756 | 2014-09-16 15:43:54 -0400 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | createPage := func(r pagination.LastHTTPResponse) pagination.Page { |
Jon Perritt | 8c93a30 | 2014-09-28 22:35:57 -0500 | [diff] [blame] | 48 | p := ObjectPage{pagination.MarkerPageBase{LastHTTPResponse: r}} |
Ash Wilson | ca6f756 | 2014-09-16 15:43:54 -0400 | [diff] [blame] | 49 | p.MarkerPageBase.Owner = p |
| 50 | return p |
Jon Perritt | 816d2a0 | 2014-03-11 20:49:46 -0500 | [diff] [blame] | 51 | } |
| 52 | |
Ash Wilson | ca6f756 | 2014-09-16 15:43:54 -0400 | [diff] [blame] | 53 | pager := pagination.NewPager(c, url, createPage) |
| 54 | pager.Headers = headers |
| 55 | return pager |
Jon Perritt | 816d2a0 | 2014-03-11 20:49:46 -0500 | [diff] [blame] | 56 | } |
| 57 | |
Jon Perritt | 8c93a30 | 2014-09-28 22:35:57 -0500 | [diff] [blame] | 58 | // DownloadOpts is a structure that holds parameters for downloading an object. |
| 59 | type DownloadOpts struct { |
| 60 | IfMatch string `h:"If-Match"` |
| 61 | IfModifiedSince time.Time `h:"If-Modified-Since"` |
| 62 | IfNoneMatch string `h:"If-None-Match"` |
| 63 | IfUnmodifiedSince time.Time `h:"If-Unmodified-Since"` |
| 64 | Range string `h:"Range"` |
| 65 | Expires string `q:"expires"` |
| 66 | MultipartManifest string `q:"multipart-manifest"` |
| 67 | Signature string `q:"signature"` |
| 68 | } |
| 69 | |
Jon Perritt | 816d2a0 | 2014-03-11 20:49:46 -0500 | [diff] [blame] | 70 | // Download is a function that retrieves the content and metadata for an object. |
Jon Perritt | eb57564 | 2014-04-24 15:16:31 -0500 | [diff] [blame] | 71 | // To extract just the content, pass the DownloadResult response to the ExtractContent |
Jon Perritt | 816d2a0 | 2014-03-11 20:49:46 -0500 | [diff] [blame] | 72 | // function. |
Jon Perritt | de47eac | 2014-09-30 15:34:17 -0500 | [diff] [blame] | 73 | func Download(c *gophercloud.ServiceClient, containerName, objectName string, opts *DownloadOpts) DownloadResult { |
Jon Perritt | 5db0892 | 2014-09-30 21:32:48 -0500 | [diff] [blame] | 74 | var res DownloadResult |
Jon Perritt | 8c93a30 | 2014-09-28 22:35:57 -0500 | [diff] [blame] | 75 | |
Jon Perritt | de47eac | 2014-09-30 15:34:17 -0500 | [diff] [blame] | 76 | url := objectURL(c, containerName, objectName) |
Ash Wilson | 604320e | 2014-09-10 16:02:28 -0400 | [diff] [blame] | 77 | h := c.Provider.AuthenticatedHeaders() |
Jon Perritt | 816d2a0 | 2014-03-11 20:49:46 -0500 | [diff] [blame] | 78 | |
Jon Perritt | de47eac | 2014-09-30 15:34:17 -0500 | [diff] [blame] | 79 | if opts != nil { |
| 80 | headers, err := gophercloud.BuildHeaders(opts) |
| 81 | if err != nil { |
Jon Perritt | 5db0892 | 2014-09-30 21:32:48 -0500 | [diff] [blame] | 82 | res.Err = err |
| 83 | return res |
Jon Perritt | de47eac | 2014-09-30 15:34:17 -0500 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | for k, v := range headers { |
| 87 | h[k] = v |
| 88 | } |
| 89 | |
| 90 | query, err := gophercloud.BuildQueryString(opts) |
| 91 | if err != nil { |
Jon Perritt | 5db0892 | 2014-09-30 21:32:48 -0500 | [diff] [blame] | 92 | res.Err = err |
| 93 | return res |
Jon Perritt | de47eac | 2014-09-30 15:34:17 -0500 | [diff] [blame] | 94 | } |
| 95 | url += query.String() |
Jon Perritt | 8c93a30 | 2014-09-28 22:35:57 -0500 | [diff] [blame] | 96 | } |
| 97 | |
Jon Perritt | 816d2a0 | 2014-03-11 20:49:46 -0500 | [diff] [blame] | 98 | resp, err := perigee.Request("GET", url, perigee.Options{ |
Jon Perritt | 816d2a0 | 2014-03-11 20:49:46 -0500 | [diff] [blame] | 99 | MoreHeaders: h, |
Ash Wilson | e47ea9e | 2014-09-10 16:03:44 -0400 | [diff] [blame] | 100 | OkCodes: []int{200}, |
Jon Perritt | 816d2a0 | 2014-03-11 20:49:46 -0500 | [diff] [blame] | 101 | }) |
Jon Perritt | 5db0892 | 2014-09-30 21:32:48 -0500 | [diff] [blame] | 102 | res.Err = err |
| 103 | res.Resp = &resp.HttpResponse |
| 104 | return res |
Jon Perritt | 8c93a30 | 2014-09-28 22:35:57 -0500 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | // CreateOpts is a structure that holds parameters for creating an object. |
| 108 | type CreateOpts struct { |
| 109 | Metadata map[string]string |
| 110 | ContentDisposition string `h:"Content-Disposition"` |
| 111 | ContentEncoding string `h:"Content-Encoding"` |
| 112 | ContentLength int `h:"Content-Length"` |
| 113 | ContentType string `h:"Content-Type"` |
| 114 | CopyFrom string `h:"X-Copy-From"` |
| 115 | DeleteAfter int `h:"X-Delete-After"` |
| 116 | DeleteAt int `h:"X-Delete-At"` |
| 117 | DetectContentType string `h:"X-Detect-Content-Type"` |
| 118 | ETag string `h:"ETag"` |
| 119 | IfNoneMatch string `h:"If-None-Match"` |
| 120 | ObjectManifest string `h:"X-Object-Manifest"` |
| 121 | TransferEncoding string `h:"Transfer-Encoding"` |
| 122 | Expires string `q:"expires"` |
| 123 | MultipartManifest string `q:"multiple-manifest"` |
| 124 | Signature string `q:"signature"` |
Jon Perritt | 816d2a0 | 2014-03-11 20:49:46 -0500 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | // Create is a function that creates a new object or replaces an existing object. |
Jon Perritt | 5db0892 | 2014-09-30 21:32:48 -0500 | [diff] [blame] | 128 | func Create(c *gophercloud.ServiceClient, containerName, objectName string, content io.Reader, opts *CreateOpts) CreateResult { |
| 129 | var res CreateResult |
Jon Perritt | 816d2a0 | 2014-03-11 20:49:46 -0500 | [diff] [blame] | 130 | var reqBody []byte |
| 131 | |
Jon Perritt | de47eac | 2014-09-30 15:34:17 -0500 | [diff] [blame] | 132 | url := objectURL(c, containerName, objectName) |
Ash Wilson | 604320e | 2014-09-10 16:02:28 -0400 | [diff] [blame] | 133 | h := c.Provider.AuthenticatedHeaders() |
Jon Perritt | 816d2a0 | 2014-03-11 20:49:46 -0500 | [diff] [blame] | 134 | |
Jon Perritt | de47eac | 2014-09-30 15:34:17 -0500 | [diff] [blame] | 135 | if opts != nil { |
| 136 | headers, err := gophercloud.BuildHeaders(opts) |
| 137 | if err != nil { |
Jon Perritt | 5db0892 | 2014-09-30 21:32:48 -0500 | [diff] [blame] | 138 | res.Err = err |
| 139 | return res |
Jon Perritt | de47eac | 2014-09-30 15:34:17 -0500 | [diff] [blame] | 140 | } |
Jon Perritt | 8c93a30 | 2014-09-28 22:35:57 -0500 | [diff] [blame] | 141 | |
Jon Perritt | de47eac | 2014-09-30 15:34:17 -0500 | [diff] [blame] | 142 | for k, v := range headers { |
| 143 | h[k] = v |
| 144 | } |
Jon Perritt | 816d2a0 | 2014-03-11 20:49:46 -0500 | [diff] [blame] | 145 | |
Jon Perritt | de47eac | 2014-09-30 15:34:17 -0500 | [diff] [blame] | 146 | for k, v := range opts.Metadata { |
| 147 | h["X-Object-Meta-"+k] = v |
| 148 | } |
Jon Perritt | 816d2a0 | 2014-03-11 20:49:46 -0500 | [diff] [blame] | 149 | |
Jon Perritt | de47eac | 2014-09-30 15:34:17 -0500 | [diff] [blame] | 150 | query, err := gophercloud.BuildQueryString(opts) |
| 151 | if err != nil { |
Jon Perritt | 5db0892 | 2014-09-30 21:32:48 -0500 | [diff] [blame] | 152 | res.Err = err |
| 153 | return res |
Jon Perritt | de47eac | 2014-09-30 15:34:17 -0500 | [diff] [blame] | 154 | } |
Jon Perritt | 5db0892 | 2014-09-30 21:32:48 -0500 | [diff] [blame] | 155 | |
Jon Perritt | de47eac | 2014-09-30 15:34:17 -0500 | [diff] [blame] | 156 | url += query.String() |
Jon Perritt | 8c93a30 | 2014-09-28 22:35:57 -0500 | [diff] [blame] | 157 | } |
Jon Perritt | 816d2a0 | 2014-03-11 20:49:46 -0500 | [diff] [blame] | 158 | |
Jon Perritt | 816d2a0 | 2014-03-11 20:49:46 -0500 | [diff] [blame] | 159 | if content != nil { |
Jon Perritt | 884e031 | 2014-08-14 17:25:38 -0500 | [diff] [blame] | 160 | reqBody = make([]byte, 0) |
Ash Wilson | 604320e | 2014-09-10 16:02:28 -0400 | [diff] [blame] | 161 | _, err := content.Read(reqBody) |
Jon Perritt | 816d2a0 | 2014-03-11 20:49:46 -0500 | [diff] [blame] | 162 | if err != nil { |
Jon Perritt | 5db0892 | 2014-09-30 21:32:48 -0500 | [diff] [blame] | 163 | res.Err = err |
| 164 | return res |
Jon Perritt | 816d2a0 | 2014-03-11 20:49:46 -0500 | [diff] [blame] | 165 | } |
| 166 | } |
| 167 | |
Jon Perritt | 5db0892 | 2014-09-30 21:32:48 -0500 | [diff] [blame] | 168 | resp, err := perigee.Request("PUT", url, perigee.Options{ |
Jon Perritt | 816d2a0 | 2014-03-11 20:49:46 -0500 | [diff] [blame] | 169 | ReqBody: reqBody, |
| 170 | MoreHeaders: h, |
Ash Wilson | e47ea9e | 2014-09-10 16:03:44 -0400 | [diff] [blame] | 171 | OkCodes: []int{201}, |
Jon Perritt | 816d2a0 | 2014-03-11 20:49:46 -0500 | [diff] [blame] | 172 | }) |
Jon Perritt | 5db0892 | 2014-09-30 21:32:48 -0500 | [diff] [blame] | 173 | res.Resp = &resp.HttpResponse |
| 174 | res.Err = err |
| 175 | return res |
Jon Perritt | 816d2a0 | 2014-03-11 20:49:46 -0500 | [diff] [blame] | 176 | } |
| 177 | |
Jon Perritt | 8c93a30 | 2014-09-28 22:35:57 -0500 | [diff] [blame] | 178 | // CopyOpts is a structure that holds parameters for copying one object to another. |
| 179 | type CopyOpts struct { |
| 180 | Metadata map[string]string |
| 181 | ContentDisposition string `h:"Content-Disposition"` |
| 182 | ContentEncoding string `h:"Content-Encoding"` |
| 183 | ContentType string `h:"Content-Type"` |
| 184 | Destination string `h:"Destination,required"` |
| 185 | } |
| 186 | |
Jon Perritt | 816d2a0 | 2014-03-11 20:49:46 -0500 | [diff] [blame] | 187 | // Copy is a function that copies one object to another. |
Jon Perritt | 5db0892 | 2014-09-30 21:32:48 -0500 | [diff] [blame] | 188 | func Copy(c *gophercloud.ServiceClient, containerName, objectName string, opts *CopyOpts) CopyResult { |
| 189 | var res CopyResult |
Ash Wilson | 604320e | 2014-09-10 16:02:28 -0400 | [diff] [blame] | 190 | h := c.Provider.AuthenticatedHeaders() |
Jon Perritt | 816d2a0 | 2014-03-11 20:49:46 -0500 | [diff] [blame] | 191 | |
Jon Perritt | de47eac | 2014-09-30 15:34:17 -0500 | [diff] [blame] | 192 | if opts == nil { |
Jon Perritt | 5db0892 | 2014-09-30 21:32:48 -0500 | [diff] [blame] | 193 | res.Err = fmt.Errorf("Required CopyOpts field 'Destination' not set.") |
| 194 | return res |
Jon Perritt | de47eac | 2014-09-30 15:34:17 -0500 | [diff] [blame] | 195 | } |
Jon Perritt | 8c93a30 | 2014-09-28 22:35:57 -0500 | [diff] [blame] | 196 | headers, err := gophercloud.BuildHeaders(opts) |
| 197 | if err != nil { |
Jon Perritt | 5db0892 | 2014-09-30 21:32:48 -0500 | [diff] [blame] | 198 | res.Err = err |
| 199 | return res |
Jon Perritt | 816d2a0 | 2014-03-11 20:49:46 -0500 | [diff] [blame] | 200 | } |
Jon Perritt | 8c93a30 | 2014-09-28 22:35:57 -0500 | [diff] [blame] | 201 | for k, v := range headers { |
Jon Perritt | 816d2a0 | 2014-03-11 20:49:46 -0500 | [diff] [blame] | 202 | h[k] = v |
| 203 | } |
| 204 | |
| 205 | for k, v := range opts.Metadata { |
| 206 | h["X-Object-Meta-"+k] = v |
| 207 | } |
| 208 | |
Jon Perritt | 8c93a30 | 2014-09-28 22:35:57 -0500 | [diff] [blame] | 209 | url := objectURL(c, containerName, objectName) |
Jon Perritt | 5db0892 | 2014-09-30 21:32:48 -0500 | [diff] [blame] | 210 | resp, err := perigee.Request("COPY", url, perigee.Options{ |
Jon Perritt | 8c93a30 | 2014-09-28 22:35:57 -0500 | [diff] [blame] | 211 | MoreHeaders: h, |
| 212 | OkCodes: []int{201}, |
| 213 | }) |
Jon Perritt | 5db0892 | 2014-09-30 21:32:48 -0500 | [diff] [blame] | 214 | res.Resp = &resp.HttpResponse |
| 215 | return res |
Jon Perritt | 8c93a30 | 2014-09-28 22:35:57 -0500 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | // DeleteOpts is a structure that holds parameters for deleting an object. |
| 219 | type DeleteOpts struct { |
| 220 | MultipartManifest string `q:"multipart-manifest"` |
| 221 | } |
| 222 | |
| 223 | // Delete is a function that deletes an object. |
Jon Perritt | 5db0892 | 2014-09-30 21:32:48 -0500 | [diff] [blame] | 224 | func Delete(c *gophercloud.ServiceClient, containerName, objectName string, opts *DeleteOpts) DeleteResult { |
| 225 | var res DeleteResult |
Jon Perritt | de47eac | 2014-09-30 15:34:17 -0500 | [diff] [blame] | 226 | url := objectURL(c, containerName, objectName) |
Jon Perritt | 8c93a30 | 2014-09-28 22:35:57 -0500 | [diff] [blame] | 227 | |
Jon Perritt | de47eac | 2014-09-30 15:34:17 -0500 | [diff] [blame] | 228 | if opts != nil { |
| 229 | query, err := gophercloud.BuildQueryString(opts) |
| 230 | if err != nil { |
Jon Perritt | 5db0892 | 2014-09-30 21:32:48 -0500 | [diff] [blame] | 231 | res.Err = err |
| 232 | return res |
Jon Perritt | de47eac | 2014-09-30 15:34:17 -0500 | [diff] [blame] | 233 | } |
| 234 | url += query.String() |
Jon Perritt | 8c93a30 | 2014-09-28 22:35:57 -0500 | [diff] [blame] | 235 | } |
| 236 | |
Jon Perritt | 5db0892 | 2014-09-30 21:32:48 -0500 | [diff] [blame] | 237 | resp, err := perigee.Request("DELETE", url, perigee.Options{ |
Jon Perritt | de47eac | 2014-09-30 15:34:17 -0500 | [diff] [blame] | 238 | MoreHeaders: c.Provider.AuthenticatedHeaders(), |
Jon Perritt | 8c93a30 | 2014-09-28 22:35:57 -0500 | [diff] [blame] | 239 | OkCodes: []int{204}, |
| 240 | }) |
Jon Perritt | 5db0892 | 2014-09-30 21:32:48 -0500 | [diff] [blame] | 241 | res.Resp = &resp.HttpResponse |
| 242 | res.Err = err |
| 243 | return res |
Jon Perritt | 8c93a30 | 2014-09-28 22:35:57 -0500 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | // GetOpts is a structure that holds parameters for getting an object's metadata. |
| 247 | type GetOpts struct { |
| 248 | Expires string `q:"expires"` |
| 249 | Signature string `q:"signature"` |
| 250 | } |
| 251 | |
| 252 | // Get is a function that retrieves the metadata of an object. To extract just the custom |
| 253 | // metadata, pass the GetResult response to the ExtractMetadata function. |
Jon Perritt | de47eac | 2014-09-30 15:34:17 -0500 | [diff] [blame] | 254 | func Get(c *gophercloud.ServiceClient, containerName, objectName string, opts *GetOpts) GetResult { |
Jon Perritt | 5db0892 | 2014-09-30 21:32:48 -0500 | [diff] [blame] | 255 | var res GetResult |
Jon Perritt | de47eac | 2014-09-30 15:34:17 -0500 | [diff] [blame] | 256 | url := objectURL(c, containerName, objectName) |
| 257 | |
| 258 | if opts != nil { |
| 259 | query, err := gophercloud.BuildQueryString(opts) |
| 260 | if err != nil { |
Jon Perritt | 5db0892 | 2014-09-30 21:32:48 -0500 | [diff] [blame] | 261 | res.Err = err |
| 262 | return res |
Jon Perritt | de47eac | 2014-09-30 15:34:17 -0500 | [diff] [blame] | 263 | } |
| 264 | url += query.String() |
Jon Perritt | 8c93a30 | 2014-09-28 22:35:57 -0500 | [diff] [blame] | 265 | } |
| 266 | |
Jon Perritt | 8c93a30 | 2014-09-28 22:35:57 -0500 | [diff] [blame] | 267 | resp, err := perigee.Request("HEAD", url, perigee.Options{ |
| 268 | MoreHeaders: c.Provider.AuthenticatedHeaders(), |
| 269 | OkCodes: []int{200, 204}, |
| 270 | }) |
Jon Perritt | 5db0892 | 2014-09-30 21:32:48 -0500 | [diff] [blame] | 271 | res.Err = err |
| 272 | res.Resp = &resp.HttpResponse |
| 273 | return res |
Jon Perritt | 8c93a30 | 2014-09-28 22:35:57 -0500 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | // UpdateOpts is a structure that holds parameters for updating, creating, or deleting an |
| 277 | // object's metadata. |
| 278 | type UpdateOpts struct { |
| 279 | Metadata map[string]string |
| 280 | ContentDisposition string `h:"Content-Disposition"` |
| 281 | ContentEncoding string `h:"Content-Encoding"` |
| 282 | ContentType string `h:"Content-Type"` |
| 283 | DeleteAfter int `h:"X-Delete-After"` |
| 284 | DeleteAt int `h:"X-Delete-At"` |
| 285 | DetectContentType bool `h:"X-Detect-Content-Type"` |
| 286 | } |
| 287 | |
| 288 | // Update is a function that creates, updates, or deletes an object's metadata. |
Jon Perritt | 5db0892 | 2014-09-30 21:32:48 -0500 | [diff] [blame] | 289 | func Update(c *gophercloud.ServiceClient, containerName, objectName string, opts *UpdateOpts) UpdateResult { |
| 290 | var res UpdateResult |
Jon Perritt | 8c93a30 | 2014-09-28 22:35:57 -0500 | [diff] [blame] | 291 | h := c.Provider.AuthenticatedHeaders() |
| 292 | |
Jon Perritt | de47eac | 2014-09-30 15:34:17 -0500 | [diff] [blame] | 293 | if opts != nil { |
| 294 | headers, err := gophercloud.BuildHeaders(opts) |
| 295 | if err != nil { |
Jon Perritt | 5db0892 | 2014-09-30 21:32:48 -0500 | [diff] [blame] | 296 | res.Err = err |
| 297 | return res |
Jon Perritt | de47eac | 2014-09-30 15:34:17 -0500 | [diff] [blame] | 298 | } |
Jon Perritt | 8c93a30 | 2014-09-28 22:35:57 -0500 | [diff] [blame] | 299 | |
Jon Perritt | de47eac | 2014-09-30 15:34:17 -0500 | [diff] [blame] | 300 | for k, v := range headers { |
| 301 | h[k] = v |
| 302 | } |
Jon Perritt | 8c93a30 | 2014-09-28 22:35:57 -0500 | [diff] [blame] | 303 | |
Jon Perritt | de47eac | 2014-09-30 15:34:17 -0500 | [diff] [blame] | 304 | for k, v := range opts.Metadata { |
| 305 | h["X-Object-Meta-"+k] = v |
| 306 | } |
Jon Perritt | 8c93a30 | 2014-09-28 22:35:57 -0500 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | url := objectURL(c, containerName, objectName) |
Jon Perritt | 5db0892 | 2014-09-30 21:32:48 -0500 | [diff] [blame] | 310 | resp, err := perigee.Request("POST", url, perigee.Options{ |
Jon Perritt | 816d2a0 | 2014-03-11 20:49:46 -0500 | [diff] [blame] | 311 | MoreHeaders: h, |
Ash Wilson | e47ea9e | 2014-09-10 16:03:44 -0400 | [diff] [blame] | 312 | OkCodes: []int{202}, |
Jon Perritt | 816d2a0 | 2014-03-11 20:49:46 -0500 | [diff] [blame] | 313 | }) |
Jon Perritt | 5db0892 | 2014-09-30 21:32:48 -0500 | [diff] [blame] | 314 | res.Resp = &resp.HttpResponse |
| 315 | res.Err = err |
| 316 | return res |
Jon Perritt | 816d2a0 | 2014-03-11 20:49:46 -0500 | [diff] [blame] | 317 | } |