xmlrpc

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2020 License: MIT Imports: 15 Imported by: 5

README

XML-RPC Client for Go

This is an implementation of client-side part of XML-RPC protocol in Go.

Usage

Add dependency to your project:

go get -u alexejk.io/go-xmlrpc

Use it by creating an *xmlrpc.Client and firing RPC method calls with Call().

package main

import(
    "fmt"

    "alexejk.io/go-xmlrpc"
)

func main() {
    client, _ := xmlrpc.NewClient("https://bugzilla.mozilla.org/xmlrpc.cgi")

    result := &struct {
        BugzillaVersion struct {
            Version string
        }
    }{}

    _ = client.Call("Bugzilla.version", nil, result)
    fmt.Printf("Version: %s\n", result.BugzillaVersion.Version)
}

If you want to customize any aspect of http.Client used to perform requests, use NewClientWithHttpClient instead. By defailt, an http.DefaultClient is used.

Argument encoding

Arguments to the remote RPC method are passed on as a *struct. This struct is encoded into XML-RPC types based on following rules:

  • Order of fields in struct type matters - fields are taken in the order they are defined on the type.
  • Numbers are to be specified as int (encoded as <int>) or float64 (encoded as <double>)
  • Both pointer and value references are accepted (pointers are followed to actual values)
Response decoding

Response is decoded following similar rules to argument encoding.

  • Order of fields is important.
  • Outer struct should contain exported field for each response parameter.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeResponse

func DecodeResponse(body []byte, v interface{}) error

func EncodeMethodCall

func EncodeMethodCall(w io.Writer, methodName string, args interface{}) error

Types

type Client

type Client struct {
	*rpc.Client
}

func NewClient

func NewClient(endpoint string) (*Client, error)

func NewClientWithHttpClient

func NewClientWithHttpClient(endpoint string, httpClient *http.Client) (*Client, error)

type Codec

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

func NewCodec

func NewCodec(endpoint *url.URL, httpClient *http.Client) *Codec

func (*Codec) Close

func (c *Codec) Close() error

func (*Codec) ReadResponseBody

func (c *Codec) ReadResponseBody(v interface{}) error

func (*Codec) ReadResponseHeader

func (c *Codec) ReadResponseHeader(resp *rpc.Response) error

func (*Codec) WriteRequest

func (c *Codec) WriteRequest(req *rpc.Request, args interface{}) error

type Fault

type Fault struct {
	Code   int
	String string
}

func (*Fault) Error

func (f *Fault) Error() string

Jump to

Keyboard shortcuts

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