Jon Perritt | dfff997 | 2014-09-22 01:14:54 -0500 | [diff] [blame] | 1 | package snapshots |
| 2 | |
Jon Perritt | d746863 | 2014-09-22 21:58:59 -0500 | [diff] [blame^] | 3 | import ( |
| 4 | "fmt" |
| 5 | |
| 6 | "github.com/mitchellh/mapstructure" |
| 7 | ) |
| 8 | |
Jon Perritt | dfff997 | 2014-09-22 01:14:54 -0500 | [diff] [blame] | 9 | type Snapshot struct { |
| 10 | CreatedAt string |
| 11 | Description string |
| 12 | ID string |
| 13 | Metadata map[string]interface{} |
| 14 | Name string |
| 15 | Size int |
| 16 | Status string |
| 17 | VolumeID string |
| 18 | } |
Jon Perritt | 56d43b2 | 2014-09-22 20:47:11 -0500 | [diff] [blame] | 19 | |
Jon Perritt | d746863 | 2014-09-22 21:58:59 -0500 | [diff] [blame^] | 20 | type GetResult struct { |
| 21 | err error |
| 22 | r map[string]interface{} |
| 23 | } |
| 24 | |
| 25 | func (gr GetResult) ExtractSnapshot() (*Snapshot, error) { |
| 26 | if gr.err != nil { |
| 27 | return nil, gr.err |
| 28 | } |
| 29 | |
| 30 | var response struct { |
| 31 | Snapshot *Snapshot `json:"snapshot"` |
| 32 | } |
| 33 | |
| 34 | err := mapstructure.Decode(gr.r, &response) |
| 35 | if err != nil { |
| 36 | return nil, fmt.Errorf("snapshots: Error decoding snapshot.GetResult: %v", err) |
| 37 | } |
| 38 | return response.Snapshot, nil |
| 39 | } |