xmlrpc

package
v1.2.8 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2025 License: MIT Imports: 20 Imported by: 1

README

Overview

xmlrpc is an implementation of client side part of XML-RPC protocol in Go language.
based on https://github.com/kolo/xmlrpc of Dmitry Maksimov (dmtmax@gmail.com).

Usage

func main() {
	client := &xmlrpc.Client{
		Endpoint: "https://bugzilla.mozilla.org/xmlrpc.cgi",
	}

	result := struct{
		Version string `xmlrpc:"version"`
	}{}

	_ = client.Call("Bugzilla.version", nil, &result) // 20250903.1

	fmt.Printf("Version: %s\n", result.Version)
}

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;
  • []byte encoded to base64;
  • slice encoded to array;

Structs encoded 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.
  • for fields tagged with ",omitempty", empty values are omitted;
  • fields tagged with "-" are omitted.

Server method can accept few arguments, to handle this case there is special approach to handle slice of empty interfaces ([]any). 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 []byte.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(r io.Reader, v any) error

func DecodeBytes

func DecodeBytes(xml []byte, v any) error

func DecodeString

func DecodeString(xml string, v any) error

func Encode

func Encode(v any) ([]byte, error)

func EncodeMethodCall

func EncodeMethodCall(w io.Writer, method string, args ...any) error

func IsFaultError

func IsFaultError(err error) bool

func IsHTTPError

func IsHTTPError(err error) bool

Types

type Client

type Client struct {
	Endpoint string

	Logger       log.Logger
	Timeout      time.Duration
	Transport    http.RoundTripper
	Authenticate func(req *http.Request)
}

func (*Client) Call

func (c *Client) Call(ctx context.Context, method string, result any, params ...any) error

type Decoder

type Decoder struct {
	*xml.Decoder
}

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

func (*Decoder) Decode

func (d *Decoder) Decode(v any) error

type Encoder

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

func NewEncoder

func NewEncoder(w io.Writer) *Encoder

func (*Encoder) Encode

func (e *Encoder) Encode(v any) error

type FaultError

type FaultError struct {
	Method      string `xmlrpc:"-"`
	FaultCode   int    `xmlrpc:"faultCode"`
	FaultString string `xmlrpc:"faultString"`
}

FaultError is returned from the server when an invalid call is made

func AsFaultError

func AsFaultError(err error) (fe *FaultError, ok bool)

func (FaultError) Error

func (fe FaultError) Error() string

type HTTPError

type HTTPError struct {
	Method     string
	StatusCode int
	Status     string
}

func AsHTTPError

func AsHTTPError(err error) (he *HTTPError, ok bool)

func (HTTPError) Error

func (he HTTPError) Error() string

type TypeMismatchError

type TypeMismatchError string

func (TypeMismatchError) Error

func (e TypeMismatchError) Error() string

Jump to

Keyboard shortcuts

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