Skip to content
This repository has been archived by the owner on Aug 31, 2021. It is now read-only.

Commit

Permalink
Merge pull request #84 from Click2Cloud/csbs_hwcloud_fix
Browse files Browse the repository at this point in the history
Fix csbs policy Operation Def field type conversion
  • Loading branch information
freesky-edward authored Nov 30, 2018
2 parents 02e7852 + 752dabd commit 6e33e83
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion openstack/csbs/v1/policies/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,31 @@ func (r *OperationDefinitionResp) UnmarshalJSON(b []byte) error {
RetentionDurationDays string `json:"retention_duration_days"`
Permanent string `json:"permanent"`
}

err := json.Unmarshal(b, &s)

if err != nil {
return err
switch err.(type) {
case *json.UnmarshalTypeError: //check if type error occurred (handles if no type conversion is required for cloud like Huawei)

var s struct {
tmp
MaxBackups int `json:"max_backups"`
RetentionDurationDays int `json:"retention_duration_days"`
Permanent bool `json:"permanent"`
}
err := json.Unmarshal(b, &s)
if err != nil {
return err
}
*r = OperationDefinitionResp(s.tmp)
r.MaxBackups = s.MaxBackups
r.RetentionDurationDays = s.RetentionDurationDays
r.Permanent = s.Permanent
return nil
default:
return err
}
}

*r = OperationDefinitionResp(s.tmp)
Expand Down

0 comments on commit 6e33e83

Please sign in to comment.