github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/networking/v2/extensions/fwaas/firewalls/results.go (about)

     1  package firewalls
     2  
     3  import (
     4  	"github.com/huaweicloud/golangsdk"
     5  	"github.com/huaweicloud/golangsdk/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  	golangsdk.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 []golangsdk.Link `json:"firewalls_links"`
    51  	}
    52  	err := r.ExtractInto(&s)
    53  	if err != nil {
    54  		return "", err
    55  	}
    56  	return golangsdk.ExtractNextURL(s.Links)
    57  }
    58  
    59  // IsEmpty checks whether a FirewallPage struct is empty.
    60  func (r FirewallPage) IsEmpty() (bool, error) {
    61  	is, err := ExtractFirewalls(r)
    62  	return len(is) == 0, err
    63  }
    64  
    65  // ExtractFirewalls accepts a Page struct, specifically a FirewallPage struct,
    66  // and extracts the elements into a slice of Firewall structs. In other words,
    67  // a generic collection is mapped into a relevant slice.
    68  func ExtractFirewalls(r pagination.Page) ([]Firewall, error) {
    69  	var s []Firewall
    70  	err := ExtractFirewallsInto(r, &s)
    71  	return s, err
    72  }
    73  
    74  // GetResult represents the result of a Get operation. Call its Extract
    75  // method to interpret it as a Firewall.
    76  type GetResult struct {
    77  	commonResult
    78  }
    79  
    80  // UpdateResult represents the result of an Update operation. Call its Extract
    81  // method to interpret it as a Firewall.
    82  type UpdateResult struct {
    83  	commonResult
    84  }
    85  
    86  // DeleteResult represents the result of a delete operation. Call its
    87  // ExtractErr method to determine if the operation succeeded or failed.
    88  type DeleteResult struct {
    89  	golangsdk.ErrResult
    90  }
    91  
    92  // CreateResult represents the result of a Create operation. Call its Extract
    93  // method to interpret it as a Firewall.
    94  type CreateResult struct {
    95  	commonResult
    96  }