github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/ecs/v1/block_devices/results.go (about) 1 package block_devices 2 3 import ( 4 "encoding/json" 5 6 "github.com/huaweicloud/golangsdk" 7 ) 8 9 type VolumeAttachment struct { 10 PciAddress string `json:"pciAddress"` 11 Size int `json:"size"` 12 BootIndex int `json:"-"` 13 } 14 15 func (r *VolumeAttachment) UnmarshalJSON(b []byte) error { 16 type tmp VolumeAttachment 17 var s struct { 18 tmp 19 BootIndex interface{} `json:"bootIndex"` 20 } 21 err := json.Unmarshal(b, &s) 22 if err != nil { 23 return err 24 } 25 26 *r = VolumeAttachment(s.tmp) 27 28 if s.BootIndex == nil { 29 r.BootIndex = -1 30 } else { 31 r.BootIndex = int(s.BootIndex.(float64)) 32 } 33 34 return err 35 } 36 37 type GetResult struct { 38 golangsdk.Result 39 } 40 41 func (r GetResult) Extract() (*VolumeAttachment, error) { 42 s := &VolumeAttachment{} 43 return s, r.ExtractInto(s) 44 } 45 46 func (r GetResult) ExtractInto(v interface{}) error { 47 return r.Result.ExtractIntoStructPtr(v, "volumeAttachment") 48 }