beam/data: Message.Parse creates a message from shell-style 'key=value' arguments
Docker-DCO-1.1-Signed-off-by: Solomon Hykes <solomon@docker.com> (github: shykes) Upstream-commit: 08686f1d2108bbe93d02e870abe8b944b1fe022b Component: engine
This commit is contained in:
@ -11,6 +11,22 @@ func Empty() Message {
|
||||
return Message(Encode(nil))
|
||||
}
|
||||
|
||||
func Parse(args []string) Message {
|
||||
data := make(map[string][]string)
|
||||
for _, word := range args {
|
||||
if strings.Contains(word, "=") {
|
||||
kv := strings.SplitN(word, "=", 2)
|
||||
key := kv[0]
|
||||
var val string
|
||||
if len(kv) == 2 {
|
||||
val = kv[1]
|
||||
}
|
||||
data[key] = []string{val}
|
||||
}
|
||||
}
|
||||
return Message(Encode(data))
|
||||
}
|
||||
|
||||
func (m Message) Add(k, v string) Message {
|
||||
data, err := Decode(string(m))
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user