blob: 537ea2e081a8468e04c4b383ecf8178d62e48bd2 [file] [log] [blame]
Ash Wilsonb73b7f82014-08-29 15:38:06 -04001package services
2
Ash Wilson64f44152014-09-05 13:45:03 -04003import (
Ash Wilsonbddac132014-09-12 14:20:16 -04004 "github.com/rackspace/gophercloud"
Ash Wilson2f5dd1f2014-09-03 14:01:37 -04005
Ash Wilson64f44152014-09-05 13:45:03 -04006 "github.com/mitchellh/mapstructure"
Ash Wilson64f44152014-09-05 13:45:03 -04007)
8
9// Service is the result of a list or information query.
10type Service struct {
Ash Wilsonb73b7f82014-08-29 15:38:06 -040011 Description *string `json:"description,omitempty"`
12 ID string `json:"id"`
13 Name string `json:"name"`
14 Type string `json:"type"`
15}
Ash Wilson2f5dd1f2014-09-03 14:01:37 -040016
Ash Wilsonbddac132014-09-12 14:20:16 -040017// ExtractServices extracts a slice of Services from a Collection acquired from List.
18func ExtractServices(page gophercloud.Page) ([]Service, error) {
19 var response struct {
20 Services []Service `mapstructure:"services"`
Ash Wilson64f44152014-09-05 13:45:03 -040021 }
22
Ash Wilsonbddac132014-09-12 14:20:16 -040023 err := mapstructure.Decode(page.(gophercloud.LinkedPage).Body, &response)
24 return response.Services, err
Ash Wilson2f5dd1f2014-09-03 14:01:37 -040025}