Jon Perritt | 85ed523 | 2015-01-16 09:14:51 -0700 | [diff] [blame] | 1 | package base |
| 2 | |
| 3 | import ( |
Jon Perritt | 6bb5944 | 2015-01-27 11:18:22 -0700 | [diff] [blame] | 4 | "errors" |
| 5 | |
Jon Perritt | 85ed523 | 2015-01-16 09:14:51 -0700 | [diff] [blame] | 6 | "github.com/rackspace/gophercloud" |
| 7 | ) |
| 8 | |
| 9 | // HomeDocument is a resource that contains all the resources for the CDN API. |
| 10 | type HomeDocument map[string]interface{} |
| 11 | |
| 12 | // GetResult represents the result of a Get operation. |
| 13 | type GetResult struct { |
| 14 | gophercloud.Result |
| 15 | } |
| 16 | |
| 17 | // Extract is a function that accepts a result and extracts a home document resource. |
| 18 | func (r GetResult) Extract() (*HomeDocument, error) { |
| 19 | if r.Err != nil { |
| 20 | return nil, r.Err |
| 21 | } |
| 22 | |
Jon Perritt | 6bb5944 | 2015-01-27 11:18:22 -0700 | [diff] [blame] | 23 | submap, ok := r.Body.(map[string]interface{})["resources"] |
| 24 | if !ok { |
| 25 | return nil, errors.New("Unexpected HomeDocument structure") |
Jon Perritt | 85ed523 | 2015-01-16 09:14:51 -0700 | [diff] [blame] | 26 | } |
Jon Perritt | 6bb5944 | 2015-01-27 11:18:22 -0700 | [diff] [blame] | 27 | casted := HomeDocument(submap.(map[string]interface{})) |
Jon Perritt | 85ed523 | 2015-01-16 09:14:51 -0700 | [diff] [blame] | 28 | |
Jon Perritt | 6bb5944 | 2015-01-27 11:18:22 -0700 | [diff] [blame] | 29 | return &casted, nil |
Jon Perritt | 85ed523 | 2015-01-16 09:14:51 -0700 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | // PingResult represents the result of a Ping operation. |
| 33 | type PingResult struct { |
| 34 | gophercloud.ErrResult |
| 35 | } |