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

     1  package channels
     2  
     3  import (
     4  	"github.com/chnsz/golangsdk/pagination"
     5  )
     6  
     7  // Channel is the structure that represents the channel detail.
     8  type Channel struct {
     9  	// Channel name.
    10  	// A channel name can contain 3 to 64 characters, starting with a letter.
    11  	// Only letters, digits, hyphens (-), and underscores (_) are allowed.
    12  	// Chinese characters must be in UTF-8 or Unicode format.
    13  	Name string `json:"name"`
    14  	// Host port of the channel.
    15  	// The value range is 1–65535.
    16  	Port int `json:"port"`
    17  	// Distribution algorithm.
    18  	// 1: WRR (default)
    19  	// 2: WLC
    20  	// 3: SH
    21  	// 4: URI hashing
    22  	BalanceStrategy int `json:"balance_strategy"`
    23  	// Member type of the channel.
    24  	// ip
    25  	// ecs (default)
    26  	MemberType string `json:"member_type"`
    27  	// Channel type.
    28  	// + 2: Server type.
    29  	// + 3: Microservice type.
    30  	Type int `json:"type"`
    31  	// Dictionary code of the channel.
    32  	// The value can contain letters, digits, hyphens (-), underscores (_), and periods (.).
    33  	DictCode string `json:"dict_code"`
    34  	// Time when the channel is created.
    35  	CreateTime string `json:"create_time"`
    36  	// Channel ID.
    37  	ID string `json:"id"`
    38  	// Channel status.
    39  	// 1: normal
    40  	// 2: abnormal
    41  	Status int `json:"status"`
    42  	// Backend server groups of the channel.
    43  	MemberGroups []MemberGroup `json:"member_groups"`
    44  	// Backend server list. Only one backend server is included if the channel type is set to 1.
    45  	Members []MemberInfo `json:"members"`
    46  	// Health check details.
    47  	VpcHealthConfig *VpcHealthConfig `json:"vpc_health_config"`
    48  	// Microservice details.
    49  	MicroserviceConfig *MicroserviceConfig `json:"microservice_info"`
    50  }
    51  
    52  // ChannelPage is a single page maximum result representing a query by offset page.
    53  type ChannelPage struct {
    54  	pagination.OffsetPageBase
    55  }
    56  
    57  // IsEmpty checks whether a ChannelPage struct is empty.
    58  func (b ChannelPage) IsEmpty() (bool, error) {
    59  	arr, err := ExtractChannels(b)
    60  	return len(arr) == 0, err
    61  }
    62  
    63  // ExtractChannels is a method to extract the list of channels.
    64  func ExtractChannels(r pagination.Page) ([]Channel, error) {
    65  	var s []Channel
    66  	err := r.(ChannelPage).Result.ExtractIntoSlicePtr(&s, "vpc_channels")
    67  	return s, err
    68  }
    69  
    70  type Member struct {
    71  	// Channel name.
    72  	// A channel name can contain 3 to 64 characters, starting with a letter.
    73  	// Only letters, digits, hyphens (-), and underscores (_) are allowed.
    74  	// Chinese characters must be in UTF-8 or Unicode format.
    75  	Name string `json:"name"`
    76  	// Channel type.
    77  	// 1: private network ELB channel (to be deprecated)
    78  	// 2: fast channel with the load balancing function
    79  	Type int `json:"type"`
    80  	// Host port of the channel.
    81  	// This parameter is valid only when the channel type is set to 2. The value range is 1–65535.
    82  	// This parameter is required if the channel type is set to 2.
    83  	Port int `json:"port"`
    84  	// Distribution algorithm.
    85  	// 1: WRR (default)
    86  	// 2: WLC
    87  	// 3: SH
    88  	// 4: URI hashing
    89  	// This parameter is mandatory if the channel type is set to 2.
    90  	BalanceStrategy int `json:"balance_strategy"`
    91  	// Member type of the channel.
    92  	// ip
    93  	// ecs (default)
    94  	// This parameter is required if the channel type is set to 2.
    95  	MemberType string `json:"member_type"`
    96  	// Time when the channel is created.
    97  	CreateTime string `json:"create_time"`
    98  	// Channel ID.
    99  	Id string `json:"id"`
   100  	// Channel status.
   101  	// 1: normal
   102  	// 2: abnormal
   103  	Status int `json:"status"`
   104  	// ID of a private network ELB channel.
   105  	// This parameter is valid only when the channel type is set to 1.
   106  	ElbId string `json:"elb_id"`
   107  }
   108  
   109  // MemberPage is a single page maximum result representing a query by offset page.
   110  type MemberPage struct {
   111  	pagination.OffsetPageBase
   112  }
   113  
   114  // IsEmpty checks whether a MemberPage struct is empty.
   115  func (b MemberPage) IsEmpty() (bool, error) {
   116  	arr, err := ExtractMembers(b)
   117  	return len(arr) == 0, err
   118  }
   119  
   120  // ExtractMembers is a method to extract the list of backend members.
   121  func ExtractMembers(r pagination.Page) ([]MemberInfo, error) {
   122  	var s []MemberInfo
   123  	err := r.(MemberPage).Result.ExtractIntoSlicePtr(&s, "members")
   124  	return s, err
   125  }