github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/iec/v1/subnets/results.go (about) 1 package subnets 2 3 import ( 4 "github.com/huaweicloud/golangsdk" 5 "github.com/huaweicloud/golangsdk/openstack/iec/v1/common" 6 "github.com/huaweicloud/golangsdk/pagination" 7 ) 8 9 // SubnetPage is the page returned by a pager when traversing over a collection 10 // of subnets. 11 type SubnetPage struct { 12 pagination.LinkedPageBase 13 } 14 15 // IsEmpty checks whether a SubnetPage struct is empty. 16 func (r SubnetPage) IsEmpty() (bool, error) { 17 is, err := ExtractSubnets(r) 18 return len(is) == 0, err 19 } 20 21 // ExtractSubnets accepts a Page struct, specifically a SubnetPage struct, 22 // and extracts the elements into a slice of Subnet structs. In other words, 23 // a generic collection is mapped into a relevant slice. 24 func ExtractSubnets(r pagination.Page) ([]common.Subnet, error) { 25 var s struct { 26 Subnets []common.Subnet `json:"subnets"` 27 } 28 err := (r.(SubnetPage)).ExtractInto(&s) 29 return s.Subnets, err 30 } 31 32 type commonResult struct { 33 golangsdk.Result 34 } 35 36 type CreateResult struct { 37 commonResult 38 } 39 40 func (r CreateResult) Extract() (*common.Subnet, error) { 41 var entity common.Subnet 42 err := r.ExtractIntoStructPtr(&entity, "subnet") 43 return &entity, err 44 } 45 46 type DeleteResult struct { 47 golangsdk.ErrResult 48 } 49 50 type GetResult struct { 51 commonResult 52 } 53 54 func (r GetResult) Extract() (*common.Subnet, error) { 55 var entity common.Subnet 56 err := r.ExtractIntoStructPtr(&entity, "subnet") 57 return &entity, err 58 } 59 60 type UpdateResult struct { 61 commonResult 62 } 63 64 type UpdateResp struct { 65 ID string `json:"id"` 66 Status string `json:"status"` 67 } 68 69 func (r UpdateResult) Extract() (*UpdateResp, error) { 70 var entity UpdateResp 71 err := r.ExtractIntoStructPtr(&entity, "subnet") 72 return &entity, err 73 } 74 75 // Subnets vpc列表对象 76 type Subnets struct { 77 Subnets []common.Subnet `json:"subnets"` 78 Count int `json:"count"` 79 } 80 81 type ListResult struct { 82 commonResult 83 } 84 85 func (r ListResult) Extract() (*Subnets, error) { 86 var entity Subnets 87 err := r.ExtractIntoStructPtr(&entity, "") 88 return &entity, err 89 }