Sort the attributes for events

This is add support for #19559
We tried sort it in client side, and it sort follow go
sort : sorts a slice of strings in increasing order.

Signed-off-by: Kai Qiang Wu(Kennan) <wkqwu@cn.ibm.com>
Upstream-commit: 746f6af9aa2a48a8910b51ebbfafac511244fd9d
Component: engine
This commit is contained in:
Kai Qiang Wu(Kennan)
2016-01-27 02:48:14 +00:00
parent 1a1060798c
commit 64053aa6b6
2 changed files with 35 additions and 1 deletions

View File

@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"io"
"sort"
"strings"
"time"
@ -99,7 +100,13 @@ func printOutput(event eventtypes.Message, output io.Writer) {
if len(event.Actor.Attributes) > 0 {
var attrs []string
for k, v := range event.Actor.Attributes {
var keys []string
for k := range event.Actor.Attributes {
keys = append(keys, k)
}
sort.Strings(keys)
for _, k := range keys {
v := event.Actor.Attributes[k]
attrs = append(attrs, fmt.Sprintf("%s=%s", k, v))
}
fmt.Fprintf(output, " (%s)", strings.Join(attrs, ", "))