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

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