xmlrpc

package
v0.0.0-...-52b58a3 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2022 License: Apache-2.0, MIT Imports: 17 Imported by: 0

README

Overview

xmlrpc is an implementation of client side part of XMLRPC protocol in Go language.

Installation

To install xmlrpc package run go get github.com/kolo/xmlrpc. To use it in application add "github.com/kolo/xmlrpc" string to import statement.

Usage

client, _ := xmlrpc.NewClient("https://bugzilla.mozilla.org/xmlrpc.cgi", nil)
result := struct{
  Version string `xmlrpc:"version"`
}{}
client.Call("Bugzilla.version", nil, &result)
fmt.Printf("Version: %s\n", result.Version) // Version: 4.2.7+

Second argument of NewClient function is an object that implements http.RoundTripper interface, it can be used to get more control over connection options. By default it initialized by http.DefaultTransport object.

Arguments encoding

xmlrpc package supports encoding of native Go data types to method arguments.

Data types encoding rules:

  • int, int8, int16, int32, int64 encoded to int;
  • float32, float64 encoded to double;
  • bool encoded to boolean;
  • string encoded to string;
  • time.Time encoded to datetime.iso8601;
  • xmlrpc.Base64 encoded to base64;
  • slice decoded to array;

Structs decoded to struct by following rules:

  • all public field become struct members;
  • field name become member name;
  • if field has xmlrpc tag, its value become member name.

Server method can accept few arguments, to handle this case there is special approach to handle slice of empty interfaces ([]interface{}). Each value of such slice encoded as separate argument.

Result decoding

Result of remote function is decoded to native Go data type.

Data types decoding rules:

  • int, i4 decoded to int, int8, int16, int32, int64;
  • double decoded to float32, float64;
  • boolean decoded to bool;
  • string decoded to string;
  • array decoded to slice;
  • structs decoded following the rules described in previous section;
  • datetime.iso8601 decoded as time.Time data type;
  • base64 decoded to string.

Implementation details

xmlrpc package contains clientCodec type, that implements rpc.ClientCodec interface of net/rpc package.

xmlrpc package works over HTTP protocol, but some internal functions and data type were made public to make it easier to create another implementation of xmlrpc that works over another protocol. To encode request body there is EncodeMethodCall function. To decode server response Response data type can be used.

Contribution

Feel free to fork the project, submit pull requests, ask questions.

Authors

Dmitry Maksimov (dmtmax@gmail.com)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// CharsetReader is a function to generate reader which converts a non UTF-8
	// charset into UTF-8.
	CharsetReader func(string, io.Reader) (io.Reader, error)
)

Functions

func EncodeMethodCall

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

func NewRequest

func NewRequest(url string, method string, args interface{}) (*http.Request, error)

Types

type Base64

type Base64 string

Base64 represents value in base64 encoding

type Client

type Client struct {
	*rpc.Client
}

func NewClient

func NewClient(requrl string, transport http.RoundTripper, timeout time.Duration) (*Client, error)

NewClient returns instance of rpc.Client object, that is used to send request to xmlrpc service.

type Params

type Params struct {
	Params []interface{}
}

type Response

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

func NewResponse

func NewResponse(data []byte, httpStatusCode int) *Response

func (*Response) Err

func (r *Response) Err() error

func (*Response) Failed

func (r *Response) Failed() bool

func (*Response) Unmarshal

func (r *Response) Unmarshal(v interface{}) error

type Struct

type Struct map[string]interface{}

type TypeMismatchError

type TypeMismatchError string

func (TypeMismatchError) Error

func (e TypeMismatchError) Error() string

type XmlRpcError

type XmlRpcError struct {
	Code           interface{}
	Err            string
	HttpStatusCode int
}

xmlrpcError represents errors returned on xmlrpc request.

func (*XmlRpcError) Error

func (e *XmlRpcError) Error() string

Error() method implements Error interface

Jump to

Keyboard shortcuts

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