github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/vpn/v5/customer_gateways/results.go (about)

     1  package customer_gateways
     2  
     3  import "github.com/chnsz/golangsdk/pagination"
     4  
     5  type CustomerGateway struct {
     6  	ID            string        `json:"id"`
     7  	Name          string        `json:"name"`
     8  	IDType        string        `json:"id_type"`
     9  	IDValue       string        `json:"id_value"`
    10  	BGPAsn        int           `json:"bgp_asn"`
    11  	IP            string        `json:"ip"`
    12  	RouteMode     string        `json:"route_mode"`
    13  	CaCertificate CaCertificate `json:"ca_certificate"`
    14  	CreatedAt     string        `json:"created_at"`
    15  	UpdatedAt     string        `json:"updated_at"`
    16  }
    17  
    18  type CaCertificate struct {
    19  	SerialNumber       string `json:"serial_number"`
    20  	SignatureAlgorithm string `json:"signature_algorithm"`
    21  	Issuer             string `json:"issuer"`
    22  	Subject            string `json:"subject"`
    23  	ExpireTime         string `json:"expire_time"`
    24  	IsUpdatable        bool   `json:"is_updatable"`
    25  }
    26  
    27  type listResp struct {
    28  	CustomerGateways []CustomerGateway `json:"customer_gateways"`
    29  	RequestId        string            `json:"request_id"`
    30  	PageInfo         pageInfo          `json:"page_info"`
    31  	TotalCount       int64             `json:"total_count"`
    32  }
    33  
    34  type pageInfo struct {
    35  	NextMarker   string `json:"next_marker"`
    36  	CurrentCount int    `json:"current_count"`
    37  }
    38  
    39  type CustomerGatewaysPage struct {
    40  	pagination.MarkerPageBase
    41  }
    42  
    43  // IsEmpty returns true if a ListResult is empty.
    44  func (r CustomerGatewaysPage) IsEmpty() (bool, error) {
    45  	resp, err := extractCustomerGateways(r)
    46  	return len(resp) == 0, err
    47  }
    48  
    49  // LastMarker returns the last marker index in a ListResult.
    50  func (r CustomerGatewaysPage) LastMarker() (string, error) {
    51  	resp, err := extractPageInfo(r)
    52  	if err != nil {
    53  		return "", err
    54  	}
    55  	return resp.NextMarker, nil
    56  }
    57  
    58  // extractCustomerGateways is a method which to extract the response to a CustomerGateway list.
    59  func extractCustomerGateways(r pagination.Page) ([]CustomerGateway, error) {
    60  	var s listResp
    61  	err := r.(CustomerGatewaysPage).Result.ExtractInto(&s)
    62  	return s.CustomerGateways, err
    63  }
    64  
    65  // extractPageInfo is a method which to extract the response of the page information.
    66  func extractPageInfo(r pagination.Page) (*pageInfo, error) {
    67  	var s listResp
    68  	err := r.(CustomerGatewaysPage).Result.ExtractInto(&s)
    69  	return &s.PageInfo, err
    70  }