| Jamie Hannaford | 93209fe | 2014-10-10 11:54:19 +0200 | [diff] [blame] | 1 | package accounts | 
|  | 2 |  | 
|  | 3 | import ( | 
| Ash Wilson | af26287 | 2014-10-20 09:32:29 -0400 | [diff] [blame] | 4 | "net/http" | 
| Jamie Hannaford | 93209fe | 2014-10-10 11:54:19 +0200 | [diff] [blame] | 5 | "strings" | 
| Jamie Hannaford | b2e129d | 2014-10-10 14:06:28 +0200 | [diff] [blame] | 6 |  | 
| Ash Wilson | af26287 | 2014-10-20 09:32:29 -0400 | [diff] [blame] | 7 | "github.com/rackspace/gophercloud" | 
| Jamie Hannaford | 93209fe | 2014-10-10 11:54:19 +0200 | [diff] [blame] | 8 | ) | 
|  | 9 |  | 
| Ash Wilson | af26287 | 2014-10-20 09:32:29 -0400 | [diff] [blame] | 10 | // GetResult is returned from a call to the Get function. | 
| Jamie Hannaford | b2e129d | 2014-10-10 14:06:28 +0200 | [diff] [blame] | 11 | type GetResult struct { | 
| Ash Wilson | af26287 | 2014-10-20 09:32:29 -0400 | [diff] [blame] | 12 | gophercloud.Result | 
| Jamie Hannaford | b2e129d | 2014-10-10 14:06:28 +0200 | [diff] [blame] | 13 | } | 
| Jamie Hannaford | 93209fe | 2014-10-10 11:54:19 +0200 | [diff] [blame] | 14 |  | 
|  | 15 | // ExtractMetadata is a function that takes a GetResult (of type *http.Response) | 
|  | 16 | // and returns the custom metatdata associated with the account. | 
| Jon Perritt | 4a59d23 | 2014-10-09 20:21:31 -0500 | [diff] [blame] | 17 | func (gr GetResult) ExtractMetadata() (map[string]string, error) { | 
|  | 18 | if gr.Err != nil { | 
|  | 19 | return nil, gr.Err | 
|  | 20 | } | 
| Jamie Hannaford | b2e129d | 2014-10-10 14:06:28 +0200 | [diff] [blame] | 21 |  | 
| Jon Perritt | 4a59d23 | 2014-10-09 20:21:31 -0500 | [diff] [blame] | 22 | metadata := make(map[string]string) | 
| Ash Wilson | af26287 | 2014-10-20 09:32:29 -0400 | [diff] [blame] | 23 | for k, v := range gr.Headers { | 
| Jamie Hannaford | 93209fe | 2014-10-10 11:54:19 +0200 | [diff] [blame] | 24 | if strings.HasPrefix(k, "X-Account-Meta-") { | 
|  | 25 | key := strings.TrimPrefix(k, "X-Account-Meta-") | 
|  | 26 | metadata[key] = v[0] | 
|  | 27 | } | 
|  | 28 | } | 
| Jon Perritt | 4a59d23 | 2014-10-09 20:21:31 -0500 | [diff] [blame] | 29 | return metadata, nil | 
|  | 30 | } | 
| Jamie Hannaford | b2e129d | 2014-10-10 14:06:28 +0200 | [diff] [blame] | 31 |  | 
| Ash Wilson | af26287 | 2014-10-20 09:32:29 -0400 | [diff] [blame] | 32 | // UpdateResult is returned from a call to the Update function. | 
| Jon Perritt | 4a59d23 | 2014-10-09 20:21:31 -0500 | [diff] [blame] | 33 | type UpdateResult struct { | 
| Ash Wilson | af26287 | 2014-10-20 09:32:29 -0400 | [diff] [blame] | 34 | gophercloud.Result | 
|  | 35 | } | 
|  | 36 |  | 
|  | 37 | // Extract returns the unmodified HTTP headers and any error conditions encountered during the | 
|  | 38 | // metadata update. | 
|  | 39 | func (ur UpdateResult) Extract() (http.Header, error) { | 
|  | 40 | return ur.Headers, ur.Err | 
| Jamie Hannaford | 93209fe | 2014-10-10 11:54:19 +0200 | [diff] [blame] | 41 | } |