diff options
| author | Shulhan <ms@kilabit.info> | 2021-05-19 13:53:01 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2021-05-19 13:53:01 +0700 |
| commit | 111a2b0408e523fb9c2a23bd60fd590c6cf88149 (patch) | |
| tree | 700484f03a914b4fc0b9c65b93b4a7ae97fc280e | |
| parent | b88099190a7b809e9cd4052edfbe8396322a9cff (diff) | |
| download | pakakeh.go-111a2b0408e523fb9c2a23bd60fd590c6cf88149.tar.xz | |
xmlrpc: marshal the struct value ordered by names
This is to make the Request or Response format consistent and to make
test working as expected.
| -rw-r--r-- | lib/xmlrpc/value.go | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/xmlrpc/value.go b/lib/xmlrpc/value.go index 01a42962..85d1e1f3 100644 --- a/lib/xmlrpc/value.go +++ b/lib/xmlrpc/value.go @@ -8,6 +8,7 @@ import ( "bytes" "fmt" "reflect" + "sort" ) // @@ -180,9 +181,17 @@ func (v *Value) String() string { fmt.Fprintf(&buf, "<base64>%s</base64>", v.In.(string)) case Struct: buf.WriteString("<struct>") - for key, value := range v.StructMembers { + keys := make([]string, 0, len(v.StructMembers)) + for key := range v.StructMembers { + if len(key) == 0 { + continue + } + keys = append(keys, key) + } + sort.Strings(keys) + for _, key := range keys { fmt.Fprintf(&buf, `<member><name>%s</name>%s</member>`, - key, value) + key, v.StructMembers[key]) } buf.WriteString("</struct>") case Array: |
