github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/compute/v2/extensions/tenantnetworks/results.go (about) 1 package tenantnetworks 2 3 import ( 4 "github.com/huaweicloud/golangsdk" 5 "github.com/huaweicloud/golangsdk/pagination" 6 ) 7 8 // A Network represents a network that a server communicates on. 9 type Network struct { 10 // CIDR is the IPv4 subnet. 11 CIDR string `json:"cidr"` 12 13 // ID is the UUID of the network. 14 ID string `json:"id"` 15 16 // Name is the common name that the network has. 17 Name string `json:"label"` 18 } 19 20 // NetworkPage stores a single page of all Networks results from a List call. 21 type NetworkPage struct { 22 pagination.SinglePageBase 23 } 24 25 // IsEmpty determines whether or not a NetworkPage is empty. 26 func (page NetworkPage) IsEmpty() (bool, error) { 27 va, err := ExtractNetworks(page) 28 return len(va) == 0, err 29 } 30 31 // ExtractNetworks interprets a page of results as a slice of Network. 32 func ExtractNetworks(r pagination.Page) ([]Network, error) { 33 var s struct { 34 Networks []Network `json:"networks"` 35 } 36 err := (r.(NetworkPage)).ExtractInto(&s) 37 return s.Networks, err 38 } 39 40 type NetworkResult struct { 41 golangsdk.Result 42 } 43 44 // Extract is a method that attempts to interpret any Network resource response 45 // as a Network struct. 46 func (r NetworkResult) Extract() (*Network, error) { 47 var s struct { 48 Network *Network `json:"network"` 49 } 50 err := r.ExtractInto(&s) 51 return s.Network, err 52 } 53 54 // GetResult is the response from a Get operation. Call its Extract method to 55 // interpret it as a Network. 56 type GetResult struct { 57 NetworkResult 58 }