divan/gorilla-xmlrpc

How to handle Array responses?

benpate opened this issue · 1 comments

Howdy. I'm using this library to connect to an XML-RPC service that returns an array -- such as a list of records that match a query. But, I'm running in to a number of errors. Unless I'm mistaken, gorilla-xmlrpc can't handle an array response, at least not as the root level result.

Unfortunately, I'm not in control of the remote XML-RPC server, so I can't just wrap the responses into a struct. So, I really need to figure out how to make this work.

I'm not sure if this project is active or not, so I'm digging in to see if I can decipher how it's working. If you have any suggestions, or even patches to make this go, please pass them on!

Go figure.. you spend hours on a proble, but as soon as you post a question publicly, then you figure out the answer. I'm posting my answer here for anyone else who has the same trouble.

Similar to functions in Go, XML-RPC can return several results for one RPC call. So, the top-level result is ALWAYS a struct. This means if your API returns an array of results, then you need to wrap that array in a struct with a single element. Then the RPC call will work as expected.