github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/waf_hw/v1/pools/results.go (about)

     1  /*
     2   Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
     3  */
     4  
     5  package pools
     6  
     7  import (
     8  	"github.com/chnsz/golangsdk/pagination"
     9  )
    10  
    11  type PoolSummaryDetail struct {
    12  	ID          string `json:"id"`
    13  	Name        string `json:"name"`
    14  	Region      string `json:"region"`
    15  	Type        string `json:"type"`
    16  	VpcID       string `json:"vpc_id"`
    17  	Description string `json:"description"`
    18  }
    19  
    20  type Pool struct {
    21  	ID          string `json:"id"`
    22  	Name        string `json:"name"`
    23  	Region      string `json:"region"`
    24  	VpcID       string `json:"vpc_id"`
    25  	Description string `json:"description"`
    26  
    27  	Option    PoolOption    `json:"option"`
    28  	Hosts     []IDNameEntry `json:"hosts"`
    29  	Instances []IDNameEntry `json:"instances"`
    30  	Bindings  []IDNameEntry `json:"bindings"`
    31  }
    32  
    33  type IDNameEntry struct {
    34  	ID   string `json:"id"`
    35  	Name string `json:"name"`
    36  }
    37  
    38  type PoolBinding struct {
    39  	ID             string `json:"id"`
    40  	LoadBalancerID string `json:"loadbalancer_id"`
    41  	WafPoolID      string `json:"waf_pool_id"`
    42  }
    43  
    44  type PoolPage struct {
    45  	pagination.PageSizeBase
    46  }
    47  
    48  // IsEmpty checks whether a RouteTablePage struct is empty.
    49  func (b PoolPage) IsEmpty() (bool, error) {
    50  	arr, err := ExtractGroups(b)
    51  	return len(arr) == 0, err
    52  }
    53  
    54  func ExtractGroups(r pagination.Page) ([]Pool, error) {
    55  	var s struct {
    56  		Total int    `json:"total"`
    57  		Items []Pool `json:"items"`
    58  	}
    59  	err := (r.(PoolPage)).ExtractInto(&s)
    60  	return s.Items, err
    61  }
    62  
    63  type BindELBPage struct {
    64  	pagination.MarkerPageBase
    65  }
    66  
    67  // LastMarker returns the last route table ID in a ListResult
    68  func (b BindELBPage) LastMarker() (string, error) {
    69  	elbs, err := ExtractBindELBs(b)
    70  	if err != nil {
    71  		return "", err
    72  	}
    73  	if len(elbs) == 0 {
    74  		return "", nil
    75  	}
    76  	return elbs[len(elbs)-1].ID, nil
    77  }
    78  
    79  // IsEmpty checks whether a RouteTablePage struct is empty.
    80  func (b BindELBPage) IsEmpty() (bool, error) {
    81  	elbs, err := ExtractBindELBs(b)
    82  	return len(elbs) == 0, err
    83  }
    84  
    85  func ExtractBindELBs(r pagination.Page) ([]PoolBinding, error) {
    86  	var s struct {
    87  		Results []PoolBinding `json:"results"`
    88  	}
    89  	err := (r.(BindELBPage)).ExtractInto(&s)
    90  	return s.Results, err
    91  }