2013-08-04 02:33:51 +04:00
|
|
|
package docker
|
|
|
|
|
|
|
|
import "sort"
|
|
|
|
|
|
|
|
type imageSorter struct {
|
|
|
|
images []APIImages
|
|
|
|
by func(i1, i2 *APIImages) bool // Closure used in the Less method.
|
|
|
|
}
|
|
|
|
|
|
|
|
// Len is part of sort.Interface.
|
|
|
|
func (s *imageSorter) Len() int {
|
|
|
|
return len(s.images)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Swap is part of sort.Interface.
|
|
|
|
func (s *imageSorter) Swap(i, j int) {
|
|
|
|
s.images[i], s.images[j] = s.images[j], s.images[i]
|
|
|
|
}
|
|
|
|
|
|
|
|
// Less is part of sort.Interface. It is implemented by calling the "by" closure in the sorter.
|
|
|
|
func (s *imageSorter) Less(i, j int) bool {
|
|
|
|
return s.by(&s.images[i], &s.images[j])
|
|
|
|
}
|
|
|
|
|
2013-08-18 09:11:34 +04:00
|
|
|
// Sort []ApiImages by most recent creation date and tag name.
|
|
|
|
func sortImagesByCreationAndTag(images []APIImages) {
|
|
|
|
creationAndTag := func(i1, i2 *APIImages) bool {
|
2013-10-06 09:44:04 +04:00
|
|
|
return i1.Created > i2.Created
|
2013-08-04 02:33:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
sorter := &imageSorter{
|
|
|
|
images: images,
|
2013-08-18 09:11:34 +04:00
|
|
|
by: creationAndTag}
|
2013-08-04 02:33:51 +04:00
|
|
|
|
|
|
|
sort.Sort(sorter)
|
|
|
|
}
|
2013-10-05 06:25:15 +04:00
|
|
|
|
|
|
|
type portSorter struct {
|
|
|
|
ports []Port
|
|
|
|
by func(i, j Port) bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *portSorter) Len() int {
|
|
|
|
return len(s.ports)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *portSorter) Swap(i, j int) {
|
|
|
|
s.ports[i], s.ports[j] = s.ports[j], s.ports[i]
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *portSorter) Less(i, j int) bool {
|
|
|
|
ip := s.ports[i]
|
|
|
|
jp := s.ports[j]
|
|
|
|
|
|
|
|
return s.by(ip, jp)
|
|
|
|
}
|
|
|
|
|
|
|
|
func sortPorts(ports []Port, predicate func(i, j Port) bool) {
|
|
|
|
s := &portSorter{ports, predicate}
|
|
|
|
sort.Sort(s)
|
|
|
|
}
|
|
|
|
|
|
|
|
type containerSorter struct {
|
|
|
|
containers []*Container
|
|
|
|
by func(i, j *Container) bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *containerSorter) Len() int {
|
|
|
|
return len(s.containers)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *containerSorter) Swap(i, j int) {
|
|
|
|
s.containers[i], s.containers[j] = s.containers[j], s.containers[i]
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *containerSorter) Less(i, j int) bool {
|
|
|
|
return s.by(s.containers[i], s.containers[j])
|
|
|
|
}
|
|
|
|
|
|
|
|
func sortContainers(containers []*Container, predicate func(i, j *Container) bool) {
|
|
|
|
s := &containerSorter{containers, predicate}
|
|
|
|
sort.Sort(s)
|
|
|
|
}
|