blob: cccea8e0f8e1b5edb933b22f4d7f04ecdb4ac866 [file] [log] [blame]
Ash Wilsonb73b7f82014-08-29 15:38:06 -04001package services
2
Ash Wilson64f44152014-09-05 13:45:03 -04003import (
Ash Wilson3c8cc772014-09-16 11:40:49 -04004 "github.com/rackspace/gophercloud/pagination"
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 Wilson3c8cc772014-09-16 11:40:49 -040017// ServicePage is a single page of Service results.
18type ServicePage struct {
19 pagination.LinkedPageBase
20}
21
22// IsEmpty returns true if the page contains no results.
23func (p ServicePage) IsEmpty() (bool, error) {
24 services, err := ExtractServices(p)
25 if err != nil {
26 return true, err
27 }
28 return len(services) == 0, nil
29}
30
Ash Wilsonbddac132014-09-12 14:20:16 -040031// ExtractServices extracts a slice of Services from a Collection acquired from List.
Ash Wilson3c8cc772014-09-16 11:40:49 -040032func ExtractServices(page pagination.Page) ([]Service, error) {
Ash Wilsonbddac132014-09-12 14:20:16 -040033 var response struct {
34 Services []Service `mapstructure:"services"`
Ash Wilson64f44152014-09-05 13:45:03 -040035 }
36
Ash Wilson3c8cc772014-09-16 11:40:49 -040037 err := mapstructure.Decode(page.(ServicePage).Body, &response)
Ash Wilsonbddac132014-09-12 14:20:16 -040038 return response.Services, err
Ash Wilson2f5dd1f2014-09-03 14:01:37 -040039}