github.com/gophercloud/gophercloud@v1.11.0/openstack/networking/v2/extensions/fwaas/firewalls/results.go (about) 1 package firewalls 2 3 import ( 4 "github.com/gophercloud/gophercloud" 5 "github.com/gophercloud/gophercloud/pagination" 6 ) 7 8 // Firewall is an OpenStack firewall. 9 type Firewall struct { 10 ID string `json:"id"` 11 Name string `json:"name"` 12 Description string `json:"description"` 13 AdminStateUp bool `json:"admin_state_up"` 14 Status string `json:"status"` 15 PolicyID string `json:"firewall_policy_id"` 16 TenantID string `json:"tenant_id"` 17 ProjectID string `json:"project_id"` 18 } 19 20 type commonResult struct { 21 gophercloud.Result 22 } 23 24 // Extract is a function that accepts a result and extracts a firewall. 25 func (r commonResult) Extract() (*Firewall, error) { 26 var s Firewall 27 err := r.ExtractInto(&s) 28 return &s, err 29 } 30 31 func (r commonResult) ExtractInto(v interface{}) error { 32 return r.Result.ExtractIntoStructPtr(v, "firewall") 33 } 34 35 func ExtractFirewallsInto(r pagination.Page, v interface{}) error { 36 return r.(FirewallPage).Result.ExtractIntoSlicePtr(v, "firewalls") 37 } 38 39 // FirewallPage is the page returned by a pager when traversing over a 40 // collection of firewalls. 41 type FirewallPage struct { 42 pagination.LinkedPageBase 43 } 44 45 // NextPageURL is invoked when a paginated collection of firewalls has reached 46 // the end of a page and the pager seeks to traverse over a new one. In order 47 // to do this, it needs to construct the next page's URL. 48 func (r FirewallPage) NextPageURL() (string, error) { 49 var s struct { 50 Links []gophercloud.Link `json:"firewalls_links"` 51 } 52 err := r.ExtractInto(&s) 53 if err != nil { 54 return "", err 55 } 56 return gophercloud.ExtractNextURL(s.Links) 57 } 58 59 // IsEmpty checks whether a FirewallPage struct is empty. 60 func (r FirewallPage) IsEmpty() (bool, error) { 61 if r.StatusCode == 204 { 62 return true, nil 63 } 64 65 is, err := ExtractFirewalls(r) 66 return len(is) == 0, err 67 } 68 69 // ExtractFirewalls accepts a Page struct, specifically a FirewallPage struct, 70 // and extracts the elements into a slice of Firewall structs. In other words, 71 // a generic collection is mapped into a relevant slice. 72 func ExtractFirewalls(r pagination.Page) ([]Firewall, error) { 73 var s []Firewall 74 err := ExtractFirewallsInto(r, &s) 75 return s, err 76 } 77 78 // GetResult represents the result of a Get operation. Call its Extract 79 // method to interpret it as a Firewall. 80 type GetResult struct { 81 commonResult 82 } 83 84 // UpdateResult represents the result of an Update operation. Call its Extract 85 // method to interpret it as a Firewall. 86 type UpdateResult struct { 87 commonResult 88 } 89 90 // DeleteResult represents the result of a delete operation. Call its 91 // ExtractErr method to determine if the operation succeeded or failed. 92 type DeleteResult struct { 93 gophercloud.ErrResult 94 } 95 96 // CreateResult represents the result of a Create operation. Call its Extract 97 // method to interpret it as a Firewall. 98 type CreateResult struct { 99 commonResult 100 }