xml

package
v0.0.0-...-ac6f559 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 4, 2019 License: BSD-3-Clause Imports: 16 Imported by: 9

Documentation

Overview

XML-RPC implementation for the Gorilla/RPC toolkit.

It's built on top of AlexStocks/gorilla-rpc package in Go(Golang) language and implements XML-RPC, according to it's specification. Unlike net/rpc from Go strlib, AlexStocks/gorilla-rpc allows usage of HTTP POST requests for RPC.

XML-RPC spec: http://xmlrpc.scripting.com/spec.html

Installation

Assuming you already imported AlexStocks/gorilla-rpc, use the following command:

go get github.com/AlexStocks/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

View Source
var (
	FaultInvalidMethodName    = Fault{Code: -32601, String: "Requested Method Not Found"}
	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

func DecodeClientResponse(r io.Reader, reply interface{}) error

DecodeClientResponse decodes the response body of a client request into the interface reply.

func EncodeClientRequest

func EncodeClientRequest(method string, args interface{}) ([]byte, error)

EncodeClientRequest encodes parameters for a XML-RPC client request.

func Fault2XML

func Fault2XML(fault Fault, buffer io.Writer)

Fault2XML is a quick 'marshalling' replacemnt for the Fault case.

func RPC2XML

func RPC2XML(value interface{}, writer io.Writer) error

func RPCParams2XMLForMulticall

func RPCParams2XMLForMulticall(rpc interface{}, writer io.Writer) error

Types

type Codec

type Codec struct {
	// contains filtered or unexported fields
}

Codec creates a CodecRequest to process each request.

func NewCodec

func NewCodec() *Codec

NewCodec returns a new XML-RPC Codec.

func (*Codec) GetMethodName

func (c *Codec) GetMethodName(method string) string

func (*Codec) Methods

func (c *Codec) Methods() []string

func (*Codec) NewRequest

func (c *Codec) NewRequest(r *http.Request) rpc.CodecRequest

NewRequest returns a CodecRequest.

func (*Codec) RegisterAlias

func (c *Codec) RegisterAlias(alias, method string)

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

type Fault

type Fault struct {
	Code   int    `xml:"faultCode"`
	String string `xml:"faultString"`
}

Fault represents XML-RPC Fault.

func (Fault) Error

func (f Fault) Error() string

Error satisifies error interface for Fault.

type ServerRequest

type ServerRequest struct {
	// Name   xml.Name `xml:"methodCall"`
	Method string `xml:"methodName"`
	// contains filtered or unexported fields
}

type XMLStruct

type XMLStruct interface {
	MarshalXML() string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL