github.com/vmware/govmomi@v0.51.0/event/sort.go (about) 1 // © Broadcom. All Rights Reserved. 2 // The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. 3 // SPDX-License-Identifier: Apache-2.0 4 5 package event 6 7 import ( 8 "sort" 9 10 "github.com/vmware/govmomi/vim25/types" 11 ) 12 13 // Sort events in ascending order base on Key 14 // From the EventHistoryCollector.latestPage sdk docs: 15 // 16 // The "oldest event" is the one with the smallest key (event ID). 17 // The events in the returned page are unordered. 18 func Sort(events []types.BaseEvent) { 19 sort.Sort(baseEvent(events)) 20 } 21 22 type baseEvent []types.BaseEvent 23 24 func (d baseEvent) Len() int { 25 return len(d) 26 } 27 28 func (d baseEvent) Less(i, j int) bool { 29 return d[i].GetEvent().Key < d[j].GetEvent().Key 30 } 31 32 func (d baseEvent) Swap(i, j int) { 33 d[i], d[j] = d[j], d[i] 34 }