beam/data: convenience Message.Pretty() function
Docker-DCO-1.1-Signed-off-by: Solomon Hykes <solomon@docker.com> (github: shykes) Upstream-commit: eca6fecb590b1a3107beb910f8df5aef0da457e6 Component: engine
This commit is contained in:
@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user