github.com/gophercloud/gophercloud@v1.14.1/openstack/networking/v2/extensions/layer3/portforwarding/results.go (about) 1 package portforwarding 2 3 import ( 4 "github.com/gophercloud/gophercloud" 5 "github.com/gophercloud/gophercloud/pagination" 6 ) 7 8 type PortForwarding struct { 9 // The ID of the floating IP port forwarding 10 ID string `json:"id"` 11 12 // A text describing the rule, which helps users to manage/find easily 13 // theirs rules. 14 Description string `json:"description"` 15 16 // The ID of the Neutron port associated to the floating IP port forwarding. 17 InternalPortID string `json:"internal_port_id"` 18 19 // The TCP/UDP/other protocol port number of the port forwarding’s floating IP address. 20 ExternalPort int `json:"external_port"` 21 22 // The IP protocol used in the floating IP port forwarding. 23 Protocol string `json:"protocol"` 24 25 // The TCP/UDP/other protocol port number of the Neutron port fixed 26 // IP address associated to the floating ip port forwarding. 27 InternalPort int `json:"internal_port"` 28 29 // The fixed IPv4 address of the Neutron port associated 30 // to the floating IP port forwarding. 31 InternalIPAddress string `json:"internal_ip_address"` 32 } 33 34 type commonResult struct { 35 gophercloud.Result 36 } 37 38 // CreateResult represents the result of a create operation. Call its Extract 39 // method to interpret it as a PortForwarding. 40 type CreateResult struct { 41 commonResult 42 } 43 44 // GetResult represents the result of a get operation. Call its Extract 45 // method to interpret it as a PortForwarding. 46 type GetResult struct { 47 commonResult 48 } 49 50 // UpdateResult represents the result of an update operation. Call its Extract 51 // method to interpret it as a PortForwarding. 52 type UpdateResult struct { 53 commonResult 54 } 55 56 // DeleteResult represents the result of a delete operation. Call its 57 // ExtractErr method to determine if the request succeeded or failed. 58 type DeleteResult struct { 59 gophercloud.ErrResult 60 } 61 62 // Extract will extract a Port Forwarding resource from a result. 63 func (r commonResult) Extract() (*PortForwarding, error) { 64 var s PortForwarding 65 err := r.ExtractInto(&s) 66 return &s, err 67 } 68 69 func (r commonResult) ExtractInto(v interface{}) error { 70 return r.Result.ExtractIntoStructPtr(v, "port_forwarding") 71 } 72 73 // PortForwardingPage is the page returned by a pager when traversing over a 74 // collection of port forwardings. 75 type PortForwardingPage struct { 76 pagination.LinkedPageBase 77 } 78 79 // NextPageURL is invoked when a paginated collection of port forwardings has 80 // reached the end of a page and the pager seeks to traverse over a new one. 81 // In order to do this, it needs to construct the next page's URL. 82 func (r PortForwardingPage) NextPageURL() (string, error) { 83 var s struct { 84 Links []gophercloud.Link `json:"port_forwarding_links"` 85 } 86 err := r.ExtractInto(&s) 87 if err != nil { 88 return "", err 89 } 90 return gophercloud.ExtractNextURL(s.Links) 91 } 92 93 // IsEmpty checks whether a PortForwardingPage struct is empty. 94 func (r PortForwardingPage) IsEmpty() (bool, error) { 95 if r.StatusCode == 204 { 96 return true, nil 97 } 98 99 is, err := ExtractPortForwardings(r) 100 return len(is) == 0, err 101 } 102 103 // ExtractPortForwardings accepts a Page struct, specifically a PortForwardingPage 104 // struct, and extracts the elements into a slice of PortForwarding structs. In 105 // other words, a generic collection is mapped into a relevant slice. 106 func ExtractPortForwardings(r pagination.Page) ([]PortForwarding, error) { 107 var s struct { 108 PortForwardings []PortForwarding `json:"port_forwardings"` 109 } 110 err := (r.(PortForwardingPage)).ExtractInto(&s) 111 return s.PortForwardings, err 112 }