github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/networking/v2/extensions/fwaas_v2/firewall_groups/results.go (about) 1 package firewall_groups 2 3 import ( 4 "github.com/huaweicloud/golangsdk" 5 "github.com/huaweicloud/golangsdk/pagination" 6 //"fmt" 7 ) 8 9 // FirewallGroup is an OpenStack firewall_group. 10 type FirewallGroup struct { 11 ID string `json:"id"` 12 Name string `json:"name"` 13 Description string `json:"description"` 14 AdminStateUp bool `json:"admin_state_up"` 15 Status string `json:"status"` 16 IngressPolicyID string `json:"ingress_firewall_policy_id"` 17 EgressPolicyID string `json:"egress_firewall_policy_id"` 18 TenantID string `json:"tenant_id"` 19 } 20 21 type commonResult struct { 22 golangsdk.Result 23 } 24 25 // Extract is a function that accepts a result and extracts a firewall. 26 func (r commonResult) Extract() (*FirewallGroup, error) { 27 var s FirewallGroup 28 //fmt.Printf("Extracting %s.\n", r.PrettyPrintJSON()) 29 err := r.ExtractInto(&s) 30 //fmt.Printf("Extracted %+v.\n", s) 31 return &s, err 32 } 33 34 func (r commonResult) ExtractInto(v interface{}) error { 35 return r.Result.ExtractIntoStructPtr(v, "firewall_group") 36 } 37 38 func ExtractFirewallGroupsInto(r pagination.Page, v interface{}) error { 39 return r.(FirewallGroupPage).Result.ExtractIntoSlicePtr(v, "firewall_groups") 40 } 41 42 // FirewallPage is the page returned by a pager when traversing over a 43 // collection of firewalls. 44 type FirewallGroupPage struct { 45 pagination.LinkedPageBase 46 } 47 48 // NextPageURL is invoked when a paginated collection of firewalls has reached 49 // the end of a page and the pager seeks to traverse over a new one. In order 50 // to do this, it needs to construct the next page's URL. 51 func (r FirewallGroupPage) NextPageURL() (string, error) { 52 var s struct { 53 Links []golangsdk.Link `json:"firewalls_links"` 54 } 55 err := r.ExtractInto(&s) 56 if err != nil { 57 return "", err 58 } 59 return golangsdk.ExtractNextURL(s.Links) 60 } 61 62 // IsEmpty checks whether a FirewallPage struct is empty. 63 func (r FirewallGroupPage) IsEmpty() (bool, error) { 64 is, err := ExtractFirewallGroups(r) 65 return len(is) == 0, err 66 } 67 68 // ExtractFirewalls accepts a Page struct, specifically a RouterPage struct, 69 // and extracts the elements into a slice of Router structs. In other words, 70 // a generic collection is mapped into a relevant slice. 71 func ExtractFirewallGroups(r pagination.Page) ([]FirewallGroup, error) { 72 var s []FirewallGroup 73 err := ExtractFirewallGroupsInto(r, &s) 74 return s, err 75 } 76 77 // GetResult represents the result of a get operation. 78 type GetResult struct { 79 commonResult 80 } 81 82 // UpdateResult represents the result of an update operation. 83 type UpdateResult struct { 84 commonResult 85 } 86 87 // DeleteResult represents the result of a delete operation. 88 type DeleteResult struct { 89 golangsdk.ErrResult 90 } 91 92 // CreateResult represents the result of a create operation. 93 type CreateResult struct { 94 commonResult 95 }