mirror of
https://github.com/bcicen/ctop.git
synced 2025-12-06 15:16:41 +08:00
move filter into own function
This commit is contained in:
22
sort.go
22
sort.go
@@ -1,6 +1,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
|
||||
"github.com/bcicen/ctop/config"
|
||||
)
|
||||
|
||||
@@ -34,4 +37,23 @@ func (a Containers) Less(i, j int) bool {
|
||||
return f(a[i], a[j])
|
||||
}
|
||||
|
||||
func (a Containers) Filter() (filtered []*Container) {
|
||||
filter := config.GetVal("filterStr")
|
||||
re := regexp.MustCompile(fmt.Sprintf(".*%s", filter))
|
||||
|
||||
for _, c := range a {
|
||||
// Apply name filter
|
||||
if re.FindAllString(c.name, 1) == nil {
|
||||
continue
|
||||
}
|
||||
// Apply state filter
|
||||
if !config.GetSwitchVal("allContainers") && c.state != "running" {
|
||||
continue
|
||||
}
|
||||
filtered = append(filtered, c)
|
||||
}
|
||||
|
||||
return filtered
|
||||
}
|
||||
|
||||
func sumNet(c *Container) int64 { return c.metrics.NetRx + c.metrics.NetTx }
|
||||
|
||||
Reference in New Issue
Block a user