Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,18 @@ For the better understanding, I use terms 'rpc2xml' and 'xml2rpc' instead of 'ma

### Supported types ###

| XML-RPC | Golang |
| ---------------- | ------------- |
| int, i4 | int |
| double | float64 |
| boolean | bool |
| string | string |
| dateTime.iso8601 | time.Time |
| base64 | []byte |
| struct | struct |
| array | []interface{} |
| nil | nil |
| XML-RPC | Golang |
| ---------------- | ---------------------- |
| int, i4 | int |
| double | float64 |
| boolean | bool |
| string | string |
| dateTime.iso8601 | time.Time |
| base64 | []byte |
| struct | struct |
| struct | map[string]interface{} |
| array | []interface{} |
| nil | nil |

### TODO ###

Expand Down
1 change: 1 addition & 0 deletions xml/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ The following types are supported:
dateTime.iso8601 time.Time
base64 []byte
struct struct
struct map[string]interface{}
array []interface{}
nil nil

Expand Down
16 changes: 16 additions & 0 deletions xml/rpc2xml.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ func rpc2XML(value interface{}) (string, error) {
out += string2XML(value.(string))
case reflect.Bool:
out += bool2XML(value.(bool))
case reflect.Map:
out += mapStruct2XML(value)
case reflect.Struct:
if reflect.TypeOf(value).String() != "time.Time" {
out += struct2XML(value)
Expand Down Expand Up @@ -95,6 +97,20 @@ func string2XML(value string) string {
return fmt.Sprintf("<string>%s</string>", value)
}

func mapStruct2XML(value interface{})(out string){
switch tmpMap := value.(type) {
case map[string]interface{}:
out += "<struct>"
for key, val := range tmpMap {
field_value, _ := rpc2XML(val)
field_name := fmt.Sprintf("<name>%s</name>", key)
out += fmt.Sprintf("<member>%s%s</member>", field_name, field_value)
}
out += "</struct>"
}
return
}

func struct2XML(value interface{}) (out string) {
out += "<struct>"
for i := 0; i < reflect.TypeOf(value).NumField(); i++ {
Expand Down