From 4841bc922669591862814034e3f83bb6dae684f3 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Tue, 25 Mar 2014 18:19:20 -0700 Subject: [PATCH] beam/data: convenience Message.Pretty() function Docker-DCO-1.1-Signed-off-by: Solomon Hykes (github: shykes) --- beam/data/message.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/beam/data/message.go b/beam/data/message.go index b35d880..e7112c7 100644 --- a/beam/data/message.go +++ b/beam/data/message.go @@ -1,6 +1,8 @@ package data import ( + "fmt" + "strings" ) type Message string @@ -54,6 +56,18 @@ func (m Message) Get(k string) []string { 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 { return string(m) }