github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/api/cloudcontroller/ccv2/service_plan.go (about) 1 package ccv2 2 3 import ( 4 "encoding/json" 5 6 "code.cloudfoundry.org/cli/api/cloudcontroller" 7 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv2/internal" 8 ) 9 10 type ServicePlan struct { 11 GUID string 12 Name string 13 ServiceGUID string 14 } 15 16 // UnmarshalJSON helps unmarshal a Cloud Controller Service Plan response. 17 func (servicePlan *ServicePlan) UnmarshalJSON(data []byte) error { 18 var ccServicePlan struct { 19 Metadata internal.Metadata 20 Entity struct { 21 Name string `json:"name"` 22 ServiceGUID string `json:"service_guid"` 23 } 24 } 25 err := json.Unmarshal(data, &ccServicePlan) 26 if err != nil { 27 return err 28 } 29 30 servicePlan.GUID = ccServicePlan.Metadata.GUID 31 servicePlan.Name = ccServicePlan.Entity.Name 32 servicePlan.ServiceGUID = ccServicePlan.Entity.ServiceGUID 33 return nil 34 } 35 36 // GetServicePlan returns the service plan with the given GUID. 37 func (client *Client) GetServicePlan(servicePlanGUID string) (ServicePlan, Warnings, error) { 38 request, err := client.newHTTPRequest(requestOptions{ 39 RequestName: internal.GetServicePlanRequest, 40 URIParams: Params{"service_plan_guid": servicePlanGUID}, 41 }) 42 if err != nil { 43 return ServicePlan{}, nil, err 44 } 45 46 var servicePlan ServicePlan 47 response := cloudcontroller.Response{ 48 Result: &servicePlan, 49 } 50 51 err = client.connection.Make(request, &response) 52 return servicePlan, response.Warnings, err 53 }