Skip to content
Permalink
Browse files
Change synchronous boolean response to bool (#99)
The `success` fields in newer versions of CloudStack will use a `bool` value instead of a `string`, matching the behavious of asynchronious responses.

To make sure this change is backwards compatible the related types now have a custom `UnmarshalJSON` method that unmarshals the data (string or bool) into the new bool field.
  • Loading branch information
Sander van Harmelen committed May 23, 2018
1 parent 0bc5242 commit 50cce667cbf0eca36ad6ad1b9f1d808b57f39234
Showing 33 changed files with 890 additions and 52 deletions.
@@ -106,7 +106,26 @@ func (s *AlertService) ArchiveAlerts(p *ArchiveAlertsParams) (*ArchiveAlertsResp

type ArchiveAlertsResponse struct {
Displaytext string `json:"displaytext"`
Success string `json:"success"`
Success bool `json:"success"`
}

func (r *ArchiveAlertsResponse) UnmarshalJSON(b []byte) error {
var m map[string]interface{}
err := json.Unmarshal(b, &m)
if err != nil {
return err
}

if success, ok := m["success"].(string); ok {
m["success"] = success == "true"
b, err = json.Marshal(m)
if err != nil {
return err
}
}

type alias ArchiveAlertsResponse
return json.Unmarshal(b, (*alias)(r))
}

type DeleteAlertsParams struct {
@@ -191,7 +210,26 @@ func (s *AlertService) DeleteAlerts(p *DeleteAlertsParams) (*DeleteAlertsRespons

type DeleteAlertsResponse struct {
Displaytext string `json:"displaytext"`
Success string `json:"success"`
Success bool `json:"success"`
}

func (r *DeleteAlertsResponse) UnmarshalJSON(b []byte) error {
var m map[string]interface{}
err := json.Unmarshal(b, &m)
if err != nil {
return err
}

if success, ok := m["success"].(string); ok {
m["success"] = success == "true"
b, err = json.Marshal(m)
if err != nil {
return err
}
}

type alias DeleteAlertsResponse
return json.Unmarshal(b, (*alias)(r))
}

type GenerateAlertParams struct {
@@ -451,7 +451,26 @@ func (s *ClusterService) DeleteCluster(p *DeleteClusterParams) (*DeleteClusterRe

type DeleteClusterResponse struct {
Displaytext string `json:"displaytext"`
Success string `json:"success"`
Success bool `json:"success"`
}

func (r *DeleteClusterResponse) UnmarshalJSON(b []byte) error {
var m map[string]interface{}
err := json.Unmarshal(b, &m)
if err != nil {
return err
}

if success, ok := m["success"].(string); ok {
m["success"] = success == "true"
b, err = json.Marshal(m)
if err != nil {
return err
}
}

type alias DeleteClusterResponse
return json.Unmarshal(b, (*alias)(r))
}

type DisableOutOfBandManagementForClusterParams struct {
@@ -332,7 +332,26 @@ func (s *DiskOfferingService) DeleteDiskOffering(p *DeleteDiskOfferingParams) (*

type DeleteDiskOfferingResponse struct {
Displaytext string `json:"displaytext"`
Success string `json:"success"`
Success bool `json:"success"`
}

func (r *DeleteDiskOfferingResponse) UnmarshalJSON(b []byte) error {
var m map[string]interface{}
err := json.Unmarshal(b, &m)
if err != nil {
return err
}

if success, ok := m["success"].(string); ok {
m["success"] = success == "true"
b, err = json.Marshal(m)
if err != nil {
return err
}
}

type alias DeleteDiskOfferingResponse
return json.Unmarshal(b, (*alias)(r))
}

type ListDiskOfferingsParams struct {
@@ -106,7 +106,26 @@ func (s *EventService) ArchiveEvents(p *ArchiveEventsParams) (*ArchiveEventsResp

type ArchiveEventsResponse struct {
Displaytext string `json:"displaytext"`
Success string `json:"success"`
Success bool `json:"success"`
}

func (r *ArchiveEventsResponse) UnmarshalJSON(b []byte) error {
var m map[string]interface{}
err := json.Unmarshal(b, &m)
if err != nil {
return err
}

if success, ok := m["success"].(string); ok {
m["success"] = success == "true"
b, err = json.Marshal(m)
if err != nil {
return err
}
}

type alias ArchiveEventsResponse
return json.Unmarshal(b, (*alias)(r))
}

type DeleteEventsParams struct {
@@ -191,7 +210,26 @@ func (s *EventService) DeleteEvents(p *DeleteEventsParams) (*DeleteEventsRespons

type DeleteEventsResponse struct {
Displaytext string `json:"displaytext"`
Success string `json:"success"`
Success bool `json:"success"`
}

func (r *DeleteEventsResponse) UnmarshalJSON(b []byte) error {
var m map[string]interface{}
err := json.Unmarshal(b, &m)
if err != nil {
return err
}

if success, ok := m["success"].(string); ok {
m["success"] = success == "true"
b, err = json.Marshal(m)
if err != nil {
return err
}
}

type alias DeleteEventsResponse
return json.Unmarshal(b, (*alias)(r))
}

type ListEventTypesParams struct {
@@ -168,7 +168,26 @@ func (s *ExtFirewallService) DeleteExternalFirewall(p *DeleteExternalFirewallPar

type DeleteExternalFirewallResponse struct {
Displaytext string `json:"displaytext"`
Success string `json:"success"`
Success bool `json:"success"`
}

func (r *DeleteExternalFirewallResponse) UnmarshalJSON(b []byte) error {
var m map[string]interface{}
err := json.Unmarshal(b, &m)
if err != nil {
return err
}

if success, ok := m["success"].(string); ok {
m["success"] = success == "true"
b, err = json.Marshal(m)
if err != nil {
return err
}
}

type alias DeleteExternalFirewallResponse
return json.Unmarshal(b, (*alias)(r))
}

type ListExternalFirewallsParams struct {
@@ -165,7 +165,26 @@ func (s *ExtLoadBalancerService) DeleteExternalLoadBalancer(p *DeleteExternalLoa

type DeleteExternalLoadBalancerResponse struct {
Displaytext string `json:"displaytext"`
Success string `json:"success"`
Success bool `json:"success"`
}

func (r *DeleteExternalLoadBalancerResponse) UnmarshalJSON(b []byte) error {
var m map[string]interface{}
err := json.Unmarshal(b, &m)
if err != nil {
return err
}

if success, ok := m["success"].(string); ok {
m["success"] = success == "true"
b, err = json.Marshal(m)
if err != nil {
return err
}
}

type alias DeleteExternalLoadBalancerResponse
return json.Unmarshal(b, (*alias)(r))
}

type ListExternalLoadBalancersParams struct {
@@ -243,7 +243,26 @@ func (s *ExternalDeviceService) DeleteCiscoAsa1000vResource(p *DeleteCiscoAsa100

type DeleteCiscoAsa1000vResourceResponse struct {
Displaytext string `json:"displaytext"`
Success string `json:"success"`
Success bool `json:"success"`
}

func (r *DeleteCiscoAsa1000vResourceResponse) UnmarshalJSON(b []byte) error {
var m map[string]interface{}
err := json.Unmarshal(b, &m)
if err != nil {
return err
}

if success, ok := m["success"].(string); ok {
m["success"] = success == "true"
b, err = json.Marshal(m)
if err != nil {
return err
}
}

type alias DeleteCiscoAsa1000vResourceResponse
return json.Unmarshal(b, (*alias)(r))
}

type DeleteCiscoNexusVSMParams struct {
@@ -363,7 +382,26 @@ func (s *ExternalDeviceService) DeleteCiscoVnmcResource(p *DeleteCiscoVnmcResour

type DeleteCiscoVnmcResourceResponse struct {
Displaytext string `json:"displaytext"`
Success string `json:"success"`
Success bool `json:"success"`
}

func (r *DeleteCiscoVnmcResourceResponse) UnmarshalJSON(b []byte) error {
var m map[string]interface{}
err := json.Unmarshal(b, &m)
if err != nil {
return err
}

if success, ok := m["success"].(string); ok {
m["success"] = success == "true"
b, err = json.Marshal(m)
if err != nil {
return err
}
}

type alias DeleteCiscoVnmcResourceResponse
return json.Unmarshal(b, (*alias)(r))
}

type DisableCiscoNexusVSMParams struct {
@@ -940,7 +940,26 @@ func (s *HostService) DeleteHost(p *DeleteHostParams) (*DeleteHostResponse, erro

type DeleteHostResponse struct {
Displaytext string `json:"displaytext"`
Success string `json:"success"`
Success bool `json:"success"`
}

func (r *DeleteHostResponse) UnmarshalJSON(b []byte) error {
var m map[string]interface{}
err := json.Unmarshal(b, &m)
if err != nil {
return err
}

if success, ok := m["success"].(string); ok {
m["success"] = success == "true"
b, err = json.Marshal(m)
if err != nil {
return err
}
}

type alias DeleteHostResponse
return json.Unmarshal(b, (*alias)(r))
}

type DisableOutOfBandManagementForHostParams struct {
@@ -2503,5 +2522,24 @@ func (s *HostService) UpdateHostPassword(p *UpdateHostPasswordParams) (*UpdateHo

type UpdateHostPasswordResponse struct {
Displaytext string `json:"displaytext"`
Success string `json:"success"`
Success bool `json:"success"`
}

func (r *UpdateHostPasswordResponse) UnmarshalJSON(b []byte) error {
var m map[string]interface{}
err := json.Unmarshal(b, &m)
if err != nil {
return err
}

if success, ok := m["success"].(string); ok {
m["success"] = success == "true"
b, err = json.Marshal(m)
if err != nil {
return err
}
}

type alias UpdateHostPasswordResponse
return json.Unmarshal(b, (*alias)(r))
}
@@ -1887,5 +1887,24 @@ func (s *ISOService) UpdateIsoPermissions(p *UpdateIsoPermissionsParams) (*Updat

type UpdateIsoPermissionsResponse struct {
Displaytext string `json:"displaytext"`
Success string `json:"success"`
Success bool `json:"success"`
}

func (r *UpdateIsoPermissionsResponse) UnmarshalJSON(b []byte) error {
var m map[string]interface{}
err := json.Unmarshal(b, &m)
if err != nil {
return err
}

if success, ok := m["success"].(string); ok {
m["success"] = success == "true"
b, err = json.Marshal(m)
if err != nil {
return err
}
}

type alias UpdateIsoPermissionsResponse
return json.Unmarshal(b, (*alias)(r))
}

0 comments on commit 50cce66

Please sign in to comment.