From a48a9031ccca6821e9df26870bf230395414e9b3 Mon Sep 17 00:00:00 2001 From: Bradley Cicenas Date: Mon, 12 Jun 2017 13:40:52 +0000 Subject: [PATCH] move container sort to struct method --- connector/docker.go | 3 +-- connector/mock.go | 3 +-- connector/runc.go | 3 +-- container/sort.go | 2 ++ 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/connector/docker.go b/connector/docker.go index 37db06b..fcbf9cd 100644 --- a/connector/docker.go +++ b/connector/docker.go @@ -3,7 +3,6 @@ package connector import ( "fmt" - "sort" "strings" "sync" @@ -161,7 +160,7 @@ func (cm *Docker) All() (containers container.Containers) { for _, c := range cm.containers { containers = append(containers, c) } - sort.Sort(containers) + containers.Sort() containers.Filter() cm.lock.Unlock() return containers diff --git a/connector/mock.go b/connector/mock.go index 5ecbeae..fdf4073 100644 --- a/connector/mock.go +++ b/connector/mock.go @@ -4,7 +4,6 @@ package connector import ( "math/rand" - "sort" "strings" "time" @@ -72,7 +71,7 @@ func (cs *Mock) Get(id string) (*container.Container, bool) { // Return array of all containers, sorted by field func (cs *Mock) All() container.Containers { - sort.Sort(cs.containers) + cs.containers.Sort() cs.containers.Filter() return cs.containers } diff --git a/connector/runc.go b/connector/runc.go index 4b7f854..d67e103 100644 --- a/connector/runc.go +++ b/connector/runc.go @@ -5,7 +5,6 @@ import ( "io/ioutil" "os" "path/filepath" - "sort" "sync" "time" @@ -217,7 +216,7 @@ func (cm *Runc) All() (containers container.Containers) { for _, c := range cm.containers { containers = append(containers, c) } - sort.Sort(containers) + containers.Sort() containers.Filter() cm.lock.Unlock() return containers diff --git a/container/sort.go b/container/sort.go index 6142043..65b6c2b 100644 --- a/container/sort.go +++ b/container/sort.go @@ -3,6 +3,7 @@ package container import ( "fmt" "regexp" + "sort" "github.com/bcicen/ctop/config" ) @@ -89,6 +90,7 @@ func SortFields() (fields []string) { type Containers []*Container +func (a Containers) Sort() { sort.Sort(a) } func (a Containers) Len() int { return len(a) } func (a Containers) Swap(i, j int) { a[i], a[j] = a[j], a[i] } func (a Containers) Less(i, j int) bool {