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