Jon Perritt | 816d2a0 | 2014-03-11 20:49:46 -0500 | [diff] [blame] | 1 | package accounts |
| 2 | |
| 3 | import ( |
| 4 | "strings" |
| 5 | ) |
| 6 | |
Jon Perritt | bef727e | 2014-05-12 22:41:55 -0500 | [diff] [blame] | 7 | // UpdateOpts is a structure that contains parameters for updating, creating, or deleting an |
| 8 | // account's metadata. |
Jon Perritt | 816d2a0 | 2014-03-11 20:49:46 -0500 | [diff] [blame] | 9 | type UpdateOpts struct { |
| 10 | Metadata map[string]string |
| 11 | Headers map[string]string |
| 12 | } |
| 13 | |
Jon Perritt | bef727e | 2014-05-12 22:41:55 -0500 | [diff] [blame] | 14 | // GetOpts is a structure that contains parameters for getting an account's metadata. |
Jon Perritt | 816d2a0 | 2014-03-11 20:49:46 -0500 | [diff] [blame] | 15 | type GetOpts struct { |
| 16 | Headers map[string]string |
| 17 | } |
| 18 | |
Jon Perritt | eb57564 | 2014-04-24 15:16:31 -0500 | [diff] [blame] | 19 | // ExtractMetadata is a function that takes a GetResult (of type *http.Response) |
Jon Perritt | 816d2a0 | 2014-03-11 20:49:46 -0500 | [diff] [blame] | 20 | // and returns the custom metatdata associated with the account. |
Jon Perritt | eb57564 | 2014-04-24 15:16:31 -0500 | [diff] [blame] | 21 | func ExtractMetadata(gr GetResult) map[string]string { |
Jon Perritt | 816d2a0 | 2014-03-11 20:49:46 -0500 | [diff] [blame] | 22 | metadata := make(map[string]string) |
Jon Perritt | eb57564 | 2014-04-24 15:16:31 -0500 | [diff] [blame] | 23 | for k, v := range gr.Header { |
Jon Perritt | 816d2a0 | 2014-03-11 20:49:46 -0500 | [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 | } |
| 29 | return metadata |
| 30 | } |