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

     1  package routes
     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 route details and
     8  // the request information.
     9  type createResp struct {
    10  	// The response detail of the route.
    11  	Route Route `json:"route"`
    12  	// The request ID.
    13  	RequestId string `json:"request_id"`
    14  }
    15  
    16  // Route is the structure that represents the details of the route under a specified route table.
    17  type Route struct {
    18  	// The ID of the route.
    19  	ID string `json:"id"`
    20  	// The type of the route.
    21  	Type string `json:"type"`
    22  	// Whether route is the black hole route.
    23  	IsBlackHole bool `json:"is_blackhole"`
    24  	// The destination of the route.
    25  	Destination string `json:"destination"`
    26  	// The corresponding attachments.
    27  	Attachments []Attachment `json:"attachments"`
    28  	// The ID of the route table to which the route belongs.
    29  	RouteTableId string `json:"route_table_id"`
    30  	// The current status of the route.
    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  // Attachment is an object that represents the details of the corresponding route.
    39  type Attachment struct {
    40  	// The resource ID for the corresponding attachment.
    41  	ResourceId string `json:"resource_id"`
    42  	// The resource type for the corresponding attachment.
    43  	ResourceType string `json:"resource_type"`
    44  	// The ID of the corresponding attachment.
    45  	AttachmentId string `json:"attachment_id"`
    46  }
    47  
    48  // getResp is the structure that represents the API response of the 'Get' method, which contains route details and the
    49  // request information.
    50  type getResp struct {
    51  	// The response detail of the route.
    52  	Route Route `json:"route"`
    53  	// The request ID.
    54  	RequestId string `json:"request_id"`
    55  }
    56  
    57  // listResp is the structure that represents the API response of the 'List' method, which contains route list, page
    58  // details and the request information.
    59  type listResp struct {
    60  	// The list of the routes.
    61  	Routes []Route `json:"routes"`
    62  	// The request ID.
    63  	RequestId string `json:"request_id"`
    64  	// The page information.
    65  	PageInfo pageInfo `json:"page_info"`
    66  }
    67  
    68  // pageInfo is the structure that represents the page information.
    69  type pageInfo struct {
    70  	// The next marker information.
    71  	NextMarker string `json:"next_marker"`
    72  	// The number of the associations in current page.
    73  	CurrentCount int `json:"current_count"`
    74  }
    75  
    76  // RoutePage represents the response pages of the List method.
    77  type RoutePage struct {
    78  	pagination.MarkerPageBase
    79  }
    80  
    81  // IsEmpty returns true if a ListResult no route.
    82  func (r RoutePage) IsEmpty() (bool, error) {
    83  	resp, err := extractRoutes(r)
    84  	return len(resp) == 0, err
    85  }
    86  
    87  // LastMarker returns the last marker index in a ListResult.
    88  func (r RoutePage) LastMarker() (string, error) {
    89  	resp, err := extractPageInfo(r)
    90  	if err != nil {
    91  		return "", err
    92  	}
    93  	if resp.NextMarker != "" {
    94  		return "", nil
    95  	}
    96  	return resp.NextMarker, nil
    97  }
    98  
    99  // extractRoutes is a method which to extract the response of the page information.
   100  func extractPageInfo(r pagination.Page) (*pageInfo, error) {
   101  	var s listResp
   102  	err := r.(RoutePage).Result.ExtractInto(&s)
   103  	return &s.PageInfo, err
   104  }
   105  
   106  // extractRoutes is a method which to extract the response to a route list.
   107  func extractRoutes(r pagination.Page) ([]Route, error) {
   108  	var s listResp
   109  	err := r.(RoutePage).Result.ExtractInto(&s)
   110  	return s.Routes, err
   111  }
   112  
   113  // updateResp is the structure that represents the API response of the 'Update' method, which contains route details and
   114  // the request information.
   115  type updateResp struct {
   116  	// The response detail of the route.
   117  	Route Route `json:"route"`
   118  	// The request ID.
   119  	RequestId string `json:"request_id"`
   120  }