From 58d5fba9459d41fe437183d86d03b9acb9dc501d Mon Sep 17 00:00:00 2001 From: Bradley Cicenas Date: Mon, 15 May 2017 10:54:35 +0000 Subject: [PATCH] update port formatting for multi-line display --- dockersource.go | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/dockersource.go b/dockersource.go index 1c58b02..eff699c 100644 --- a/dockersource.go +++ b/dockersource.go @@ -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) {