Documentation ¶
Overview ¶
XML-RPC implementation for the Gorilla/RPC toolkit.
It's built on top of gorilla/rpc package in Go(Golang) language and implements XML-RPC, according to it's specification. Unlike net/rpc from Go strlib, gorilla/rpc allows usage of HTTP POST requests for RPC.
XML-RPC spec: http://xmlrpc.scripting.com/spec.html
Installation ¶
Assuming you already imported gorilla/rpc, use the following command:
go get github.com/divan/gorilla-xmlrpc/xml
Implementation details ¶
The main objective was to use standard encoding/xml package for XML marshalling/unmarshalling. Unfortunately, in current implementation there is no graceful way to implement common structre for marshal and unmarshal functions - marshalling doesn't handle interface{} types so far (though, it could be changed in the future). So, marshalling is implemented manually.
Unmarshalling code first creates temporary structure for unmarshalling XML into, then converts it into the passed variable using reflect package. If XML struct member's name is lowercased, it's first letter will be uppercased, as in Go/Gorilla field name must be exported(first-letter uppercased).
Marshalling code converts rpc directly to the string XML representation.
For the better understanding, I use terms 'rpc2xml' and 'xml2rpc' instead of 'marshal' and 'unmarshall'.
Types ¶
The following types are supported:
XML-RPC Golang ------- ------ int, i4 int double float64 boolean bool stringi string dateTime.iso8601 time.Time base64 []byte struct struct array []interface{} nil nil
TODO ¶
TODO list:
- Add more corner cases tests
Examples ¶
Checkout examples in examples/ directory.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( FaultInvalidParams = Fault{Code: -32602, String: "Invalid Method Parameters"} FaultWrongArgumentsNumber = Fault{Code: -32602, String: "Wrong Arguments Number"} FaultInternalError = Fault{Code: -32603, String: "Internal Server Error"} FaultApplicationError = Fault{Code: -32500, String: "Application Error"} FaultSystemError = Fault{Code: -32400, String: "System Error"} FaultDecode = Fault{Code: -32700, String: "Parsing error: not well formed"} )
Default Faults NOTE: XMLRPC spec doesn't specify any Fault codes. These codes seems to be widely accepted, and taken from the http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php
Functions ¶
func DecodeClientResponse ¶
DecodeClientResponse decodes the response body of a client request into the interface reply.
func EncodeClientRequest ¶
EncodeClientRequest encodes parameters for a XML-RPC client request.
func Snake2Camel ¶
Types ¶
type Codec ¶
type Codec struct {
// contains filtered or unexported fields
}
Codec creates a CodecRequest to process each request.
func (*Codec) NewRequest ¶
func (c *Codec) NewRequest(r *http.Request) rpc.CodecRequest
NewRequest returns a CodecRequest.
func (*Codec) RegisterAlias ¶
RegisterAlias creates a method alias
type CodecRequest ¶
type CodecRequest struct {
// contains filtered or unexported fields
}
CodecRequest decodes and encodes a single request.
func (*CodecRequest) Method ¶
func (c *CodecRequest) Method() (string, error)
Method returns the RPC method for the current request.
The method uses a dotted notation as in "Service.Method".
func (*CodecRequest) ReadRequest ¶
func (c *CodecRequest) ReadRequest(args interface{}) error
ReadRequest fills the request object for the RPC method.
args is the pointer to the Service.Args structure it gets populated from temporary XML structure
func (*CodecRequest) WriteResponse ¶
func (c *CodecRequest) WriteResponse(w http.ResponseWriter, response interface{}, methodErr error) error
WriteResponse encodes the response and writes it to the ResponseWriter.
response is the pointer to the Service.Response structure it gets encoded into the XML-RPC xml string