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:
Solomon Hykes 2014-03-25 18:19:20 -07:00
parent f295ccc72a
commit 4841bc9226

View file

@ -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)
} }