github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/er/v3/associations/results.go (about)

     1  package associations
     2  
     3  import (
     4  	"github.com/chnsz/golangsdk/pagination"
     5  )
     6  
     7  // createResp is the structure that represents the API response of the 'Create' method, which contains association
     8  // details and the request information.
     9  type createResp struct {
    10  	// The response detail of the association.
    11  	Association Association `json:"association"`
    12  	// The request ID.
    13  	RequestId string `json:"request_id"`
    14  }
    15  
    16  // Association is the structure that represents the details of the association under route table.
    17  type Association struct {
    18  	// The ID of the association.
    19  	ID string `json:"id"`
    20  	// The ID of the route table to which the association belongs.
    21  	RouteTableId string `json:"route_table_id"`
    22  	// The ID of the corresponding attachment.
    23  	AttachmentId string `json:"attachment_id"`
    24  	// The resource type for the corresponding attachment.
    25  	ResourceType string `json:"resource_type"`
    26  	// The resource ID for the corresponding attachment.
    27  	ResourceId string `json:"resource_id"`
    28  	// The configuration of the export routing policy.
    29  	RoutePolicy ExportRoutePolicy `json:"route_policy"`
    30  	// The current status of the association.
    31  	Status string `json:"state"`
    32  	// The creation time of the association.
    33  	CreatedAt string `json:"created_at"`
    34  	// The last update time of the association.
    35  	UpdatedAt string `json:"updated_at"`
    36  }
    37  
    38  // listResp is the structure that represents the API response of the 'List' method, which contains association list,
    39  // page details and the request information.
    40  type listResp struct {
    41  	// The list of the associations.
    42  	Associations []Association `json:"associations"`
    43  	// The request ID.
    44  	RequestId string `json:"request_id"`
    45  	// The page information.
    46  	PageInfo pageInfo `json:"page_info"`
    47  }
    48  
    49  // pageInfo is the structure that represents the page information.
    50  type pageInfo struct {
    51  	// The next marker information.
    52  	NextMarker string `json:"next_marker"`
    53  	// The number of the associations in current page.
    54  	CurrentCount int `json:"current_count"`
    55  }
    56  
    57  // AssociationPage represents the response pages of the List method.
    58  type AssociationPage struct {
    59  	pagination.MarkerPageBase
    60  }
    61  
    62  // IsEmpty returns true if a ListResult no association.
    63  func (r AssociationPage) IsEmpty() (bool, error) {
    64  	resp, err := extractAssociations(r)
    65  	return len(resp) == 0, err
    66  }
    67  
    68  // LastMarker returns the last marker index in a ListResult.
    69  func (r AssociationPage) LastMarker() (string, error) {
    70  	resp, err := extractPageInfo(r)
    71  	if err != nil {
    72  		return "", err
    73  	}
    74  
    75  	return resp.NextMarker, nil
    76  }
    77  
    78  // extractPageInfo is a method which to extract the response of the page information.
    79  func extractPageInfo(r pagination.Page) (*pageInfo, error) {
    80  	var s listResp
    81  	err := r.(AssociationPage).Result.ExtractInto(&s)
    82  	return &s.PageInfo, err
    83  }
    84  
    85  // ExtractAssociations is a method which to extract the response to a association list.
    86  func extractAssociations(r pagination.Page) ([]Association, error) {
    87  	var s listResp
    88  	err := r.(AssociationPage).Result.ExtractInto(&s)
    89  	return s.Associations, err
    90  }