beam/data: convenience Message.Pretty() function
Docker-DCO-1.1-Signed-off-by: Solomon Hykes <solomon@docker.com> (github: shykes)
This commit is contained in:
parent
f295ccc72a
commit
4841bc9226
1 changed files with 14 additions and 0 deletions
|
@ -1,6 +1,8 @@
|
||||||
package data
|
package data
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Message string
|
type Message string
|
||||||
|
@ -54,6 +56,18 @@ func (m Message) Get(k string) []string {
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m Message) Pretty() string {
|
||||||
|
data, err := Decode(string(m))
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
entries := make([]string, 0, len(data))
|
||||||
|
for k, values := range data {
|
||||||
|
entries = append(entries, fmt.Sprintf("%s=%s", k, strings.Join(values, ",")))
|
||||||
|
}
|
||||||
|
return strings.Join(entries, "\n")
|
||||||
|
}
|
||||||
|
|
||||||
func (m Message) String() string {
|
func (m Message) String() string {
|
||||||
return string(m)
|
return string(m)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue