Jamie Hannaford | 93209fe | 2014-10-10 11:54:19 +0200 | [diff] [blame] | 1 | package accounts |
| 2 | |
| 3 | import ( |
| 4 | "net/http" |
| 5 | "strings" |
Jamie Hannaford | b2e129d | 2014-10-10 14:06:28 +0200 | [diff] [blame^] | 6 | |
| 7 | "github.com/rackspace/gophercloud" |
Jamie Hannaford | 93209fe | 2014-10-10 11:54:19 +0200 | [diff] [blame] | 8 | ) |
| 9 | |
Jamie Hannaford | b2e129d | 2014-10-10 14:06:28 +0200 | [diff] [blame^] | 10 | type commonResult struct { |
| 11 | gophercloud.CommonResult |
| 12 | Resp *http.Response |
| 13 | } |
| 14 | |
| 15 | // GetResult represents the result of a create operation. |
| 16 | type GetResult struct { |
| 17 | commonResult |
| 18 | } |
| 19 | |
| 20 | // UpdateResult represents the result of an update operation. |
| 21 | type UpdateResult struct { |
| 22 | commonResult |
| 23 | } |
Jamie Hannaford | 93209fe | 2014-10-10 11:54:19 +0200 | [diff] [blame] | 24 | |
| 25 | // ExtractMetadata is a function that takes a GetResult (of type *http.Response) |
| 26 | // and returns the custom metatdata associated with the account. |
Jamie Hannaford | b2e129d | 2014-10-10 14:06:28 +0200 | [diff] [blame^] | 27 | func (res commonResult) ExtractMetadata() map[string]string { |
Jamie Hannaford | 93209fe | 2014-10-10 11:54:19 +0200 | [diff] [blame] | 28 | metadata := make(map[string]string) |
Jamie Hannaford | b2e129d | 2014-10-10 14:06:28 +0200 | [diff] [blame^] | 29 | |
| 30 | for k, v := range res.Resp.Header { |
Jamie Hannaford | 93209fe | 2014-10-10 11:54:19 +0200 | [diff] [blame] | 31 | if strings.HasPrefix(k, "X-Account-Meta-") { |
| 32 | key := strings.TrimPrefix(k, "X-Account-Meta-") |
| 33 | metadata[key] = v[0] |
| 34 | } |
| 35 | } |
Jamie Hannaford | b2e129d | 2014-10-10 14:06:28 +0200 | [diff] [blame^] | 36 | |
Jamie Hannaford | 93209fe | 2014-10-10 11:54:19 +0200 | [diff] [blame] | 37 | return metadata |
| 38 | } |