github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/elb/v2/listeners/results.go (about)

     1  package listeners
     2  
     3  import (
     4  	"github.com/chnsz/golangsdk"
     5  	"github.com/chnsz/golangsdk/openstack/elb/v2/l7policies"
     6  	"github.com/chnsz/golangsdk/openstack/elb/v2/pools"
     7  	"github.com/chnsz/golangsdk/pagination"
     8  )
     9  
    10  type LoadBalancerID struct {
    11  	ID string `json:"id"`
    12  }
    13  
    14  // Listener is the primary load balancing configuration object that specifies
    15  // the loadbalancer and port on which client traffic is received, as well
    16  // as other details such as the load balancing method to be use, protocol, etc.
    17  type Listener struct {
    18  	// The unique ID for the Listener.
    19  	ID string `json:"id"`
    20  
    21  	// Owner of the Listener.
    22  	TenantID string `json:"tenant_id"`
    23  
    24  	// Specifies the ID of the project to which the listener belongs. This parameter has the same meaning as tenant_id.
    25  	ProjectID string `json:"project_id"`
    26  
    27  	// Human-readable name for the Listener. Does not have to be unique.
    28  	Name string `json:"name"`
    29  
    30  	// Human-readable description for the Listener.
    31  	Description string `json:"description"`
    32  
    33  	// The protocol to loadbalance. A valid value is TCP, HTTP, or HTTPS.
    34  	Protocol string `json:"protocol"`
    35  
    36  	// The port on which to listen to client traffic that is associated with the
    37  	// Loadbalancer. A valid value is from 0 to 65535.
    38  	ProtocolPort int `json:"protocol_port"`
    39  
    40  	// The UUID of default pool. Must have compatible protocol with listener.
    41  	DefaultPoolID string `json:"default_pool_id"`
    42  
    43  	// A list of load balancer IDs.
    44  	Loadbalancers []LoadBalancerID `json:"loadbalancers"`
    45  
    46  	// The maximum number of connections allowed for the Loadbalancer.
    47  	// Default is -1, meaning no limit.
    48  	ConnLimit int `json:"connection_limit"`
    49  
    50  	// whether to use HTTP2.
    51  	Http2Enable bool `json:"http2_enable"`
    52  
    53  	// The list of references to TLS secrets.
    54  	SniContainerRefs []string `json:"sni_container_refs"`
    55  
    56  	// the ID of the CA certificate used by the listener.
    57  	CAContainerRef string `json:"client_ca_tls_container_ref"`
    58  
    59  	// A reference to a Barbican container of TLS secrets.
    60  	DefaultTlsContainerRef string `json:"default_tls_container_ref"`
    61  
    62  	// Specifies the security policy used by the listener.
    63  	TlsCiphersPolicy string `json:"tls_ciphers_policy"`
    64  
    65  	// The administrative state of the Listener. A valid value is true (UP) or false (DOWN).
    66  	AdminStateUp bool `json:"admin_state_up"`
    67  
    68  	// Pools are the pools which are part of this listener.
    69  	Pools []pools.Pool `json:"pools"`
    70  
    71  	// L7policies are the L7 policies which are part of this listener.
    72  	L7Policies []l7policies.L7Policy `json:"l7policies"`
    73  
    74  	// The provisioning status of the listener.
    75  	// This value is ACTIVE, PENDING_* or ERROR.
    76  	ProvisioningStatus string `json:"provisioning_status"`
    77  }
    78  
    79  // ListenerPage is the page returned by a pager when traversing over a
    80  // collection of listeners.
    81  type ListenerPage struct {
    82  	pagination.LinkedPageBase
    83  }
    84  
    85  // NextPageURL is invoked when a paginated collection of listeners has reached
    86  // the end of a page and the pager seeks to traverse over a new one. In order
    87  // to do this, it needs to construct the next page's URL.
    88  func (r ListenerPage) NextPageURL() (string, error) {
    89  	var s struct {
    90  		Links []golangsdk.Link `json:"listeners_links"`
    91  	}
    92  	err := r.ExtractInto(&s)
    93  	if err != nil {
    94  		return "", err
    95  	}
    96  	return golangsdk.ExtractNextURL(s.Links)
    97  }
    98  
    99  // IsEmpty checks whether a ListenerPage struct is empty.
   100  func (r ListenerPage) IsEmpty() (bool, error) {
   101  	is, err := ExtractListeners(r)
   102  	return len(is) == 0, err
   103  }
   104  
   105  // ExtractListeners accepts a Page struct, specifically a ListenerPage struct,
   106  // and extracts the elements into a slice of Listener structs. In other words,
   107  // a generic collection is mapped into a relevant slice.
   108  func ExtractListeners(r pagination.Page) ([]Listener, error) {
   109  	var s struct {
   110  		Listeners []Listener `json:"listeners"`
   111  	}
   112  	err := (r.(ListenerPage)).ExtractInto(&s)
   113  	return s.Listeners, err
   114  }
   115  
   116  type commonResult struct {
   117  	golangsdk.Result
   118  }
   119  
   120  // Extract is a function that accepts a result and extracts a listener.
   121  func (r commonResult) Extract() (*Listener, error) {
   122  	var s struct {
   123  		Listener *Listener `json:"listener"`
   124  	}
   125  	err := r.ExtractInto(&s)
   126  	return s.Listener, err
   127  }
   128  
   129  // CreateResult represents the result of a create operation. Call its Extract
   130  // method to interpret it as a Listener.
   131  type CreateResult struct {
   132  	commonResult
   133  }
   134  
   135  // GetResult represents the result of a get operation. Call its Extract
   136  // method to interpret it as a Listener.
   137  type GetResult struct {
   138  	commonResult
   139  }
   140  
   141  // UpdateResult represents the result of an update operation. Call its Extract
   142  // method to interpret it as a Listener.
   143  type UpdateResult struct {
   144  	commonResult
   145  }
   146  
   147  // DeleteResult represents the result of a delete operation. Call its
   148  // ExtractErr method to determine if the request succeeded or failed.
   149  type DeleteResult struct {
   150  	golangsdk.ErrResult
   151  }