forked from cloudfoundry/cli
/
service.go
56 lines (48 loc) · 1.4 KB
/
service.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package ccv2
import (
"encoding/json"
"code.cloudfoundry.org/cli/api/cloudcontroller"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv2/internal"
)
type Service struct {
GUID string
Label string
Description string
DocumentationURL string
}
// UnmarshalJSON helps unmarshal a Cloud Controller Service response.
func (service *Service) UnmarshalJSON(data []byte) error {
var ccService struct {
Metadata internal.Metadata
Entity struct {
Label string `json:"label"`
Description string `json:"description"`
DocumentationURL string `json:"documentation_url"`
}
}
err := json.Unmarshal(data, &ccService)
if err != nil {
return err
}
service.GUID = ccService.Metadata.GUID
service.Label = ccService.Entity.Label
service.Description = ccService.Entity.Description
service.DocumentationURL = ccService.Entity.DocumentationURL
return nil
}
// GetService returns the service with the given GUID.
func (client *Client) GetService(serviceGUID string) (Service, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetServiceRequest,
URIParams: Params{"service_guid": serviceGUID},
})
if err != nil {
return Service{}, nil, err
}
var service Service
response := cloudcontroller.Response{
Result: &service,
}
err = client.connection.Make(request, &response)
return service, response.Warnings, err
}