Files
dynamix-golang-sdk/pkg/cloudbroker/qospolicy/sorting.go

40 lines
937 B
Go
Raw Normal View History

2026-08-21 18:12:55 +04:00
package qospolicy
import "sort"
// SortByCreatedAt sorts ListQoSPolicies by the CreatedAt field in ascending order
// If inverse param is set to true, the order is reversed
func (lqp ListQoSPolicies) SortByCreatedAt(inverse bool) ListQoSPolicies {
if len(lqp.Data) < 2 {
return lqp
}
sort.Slice(lqp.Data, func(i, j int) bool {
if inverse {
return lqp.Data[i].CreatedAt > lqp.Data[j].CreatedAt
}
return lqp.Data[i].CreatedAt < lqp.Data[j].CreatedAt
})
return lqp
}
// SortByUpdatedAt sorts ListQoSPolicies by the UpdatedAt field in ascending order
// If inverse param is set to true, the order is reversed
func (lqp ListQoSPolicies) SortByUpdatedAt(inverse bool) ListQoSPolicies {
if len(lqp.Data) < 2 {
return lqp
}
sort.Slice(lqp.Data, func(i, j int) bool {
if inverse {
return lqp.Data[i].UpdatedAt > lqp.Data[j].UpdatedAt
}
return lqp.Data[i].UpdatedAt < lqp.Data[j].UpdatedAt
})
return lqp
}