update port formatting for multi-line display

This commit is contained in:
Bradley Cicenas 2017-05-15 10:54:35 +00:00
parent c76036a6f2
commit 58d5fba945
1 changed files with 13 additions and 12 deletions

View File

@ -1,6 +1,7 @@
package main
import (
"fmt"
"sort"
"strings"
"sync"
@ -61,21 +62,21 @@ func (cm *DockerContainerSource) watchEvents() {
}
func portsFormat(ports map[docker.Port][]docker.PortBinding) string {
res := ""
var exposed []string
var published []string
for k, v := range ports {
res += string(k)
if len(v) > 0 {
res += " -> ["
for i, p := range v {
res += p.HostPort
if i < len(v)-1 {
res += ","
}
}
res += "] "
if len(v) == 0 {
exposed = append(exposed, string(k))
continue
}
for _, binding := range v {
s := fmt.Sprintf("%s -> %s:%s", k, binding.HostIP, binding.HostPort)
published = append(published, s)
}
}
return res
return strings.Join(append(exposed, published...), "\n")
}
func (cm *DockerContainerSource) refresh(c *Container) {