40 lines
937 B
Go
40 lines
937 B
Go
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
|
|
}
|