Code refactor, separate discovery from manager

This commit is contained in:
Christopher LaPointe
2023-05-30 21:57:01 -04:00
parent 3974f7be85
commit f9f5e66553
10 changed files with 278 additions and 259 deletions

View File

@@ -1,9 +1,6 @@
package service
import (
"fmt"
"strings"
"github.com/docker/docker/api/types"
)
@@ -14,38 +11,3 @@ func sumNetworkBytes(networks map[string]types.NetworkStats) (recv int64, send i
}
return
}
func shortId(id string) string {
const SLEN = 8
if len(id) <= SLEN {
return id
}
return id[:SLEN]
}
func containerShort(c *types.Container) string {
var name string
if len(c.Names) > 0 {
name = trimRootPath(c.Names[0])
} else {
name = c.Image
}
return fmt.Sprintf("%s(%s)", name, shortId(c.ID))
}
func trimRootPath(s string) string {
return strings.TrimPrefix(s, "/")
}
func isRunning(c *types.Container) bool {
return c.State == "running"
}
func strSliceContains(slice []string, s string) bool {
for _, item := range slice {
if item == s {
return true
}
}
return false
}