xmlrpc

package
v0.0.0-...-9febfc8 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2025 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Overview

Package xmlrpc implements the XML-RPC client library.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Call

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

Call represents a XML-RPC call request.

func NewCall

func NewCall(method string, args ...interface{}) Call

NewCall creates a XML-RPC call.

func NewCallTimeout

func NewCallTimeout(method string, timeout time.Duration, args ...interface{}) Call

NewCallTimeout creates a XML-RPC call.

type CallBuilder

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

CallBuilder is a utility for building and executing XMLRPC requests easily. This builder allows the user to specify the different elements of an RPC call as needed in a chain. It also provides a few convenience methods for making calls that expect a return of basic types.

func NewCallBuilder

func NewCallBuilder(xmlrpc *XMLRpc) *CallBuilder

NewCallBuilder creates a new CallBuilder instance.

func (*CallBuilder) Args

func (b *CallBuilder) Args(methodArgs ...interface{}) *CallBuilder

Args sets the method arguments, in order, that will be sent with the XMLRPC call. Each passed argument must be of a data type that can be marshalled for an XMLRPC call by XMLRpc.

func (*CallBuilder) Call

func (b *CallBuilder) Call(ctx context.Context) error

Call completes the XMLRPC call build process by using what was set in other methods to execute the XMLRPC request with XMLRpc.

Note that this only returns an error if the request fails, it does not return the return values of the RPC call. To retrieve the return values of the RPC call, call Returns prior to Call.

func (*CallBuilder) CallForBool

func (b *CallBuilder) CallForBool(ctx context.Context) (bool, error)

CallForBool is a convenience method for calling an RPC method that returns a single bool. The result of the RPC method call and Call is returned.

func (*CallBuilder) CallForBoolSuccess

func (b *CallBuilder) CallForBoolSuccess(ctx context.Context) error

CallForBoolSuccess is a convenience method for calling an RPC method that returns a single bool which is true if the method is successful. Returns a non-nil error if the call fails or does not return a true bool.

func (*CallBuilder) CallForBytes

func (b *CallBuilder) CallForBytes(ctx context.Context) ([]byte, error)

CallForBytes is a convenience method for calling an RPC method that returns a single byte array. The result of the RPC method call and Call is returned.

func (*CallBuilder) CallForFloat64

func (b *CallBuilder) CallForFloat64(ctx context.Context) (float64, error)

CallForFloat64 is a convenience method for calling an RPC method that returns a single float64. The result of the RPC method call and Call is returned. Note: Python double and float XMLRPC values are both read as float64.

func (*CallBuilder) CallForInt

func (b *CallBuilder) CallForInt(ctx context.Context) (int, error)

CallForInt is a convenience method for calling an RPC method that returns a single int. The result of the RPC method call and Call is returned.

func (*CallBuilder) CallForInts

func (b *CallBuilder) CallForInts(ctx context.Context) ([]int, error)

CallForInts is a convenience method for calling an RPC method that returns a single int array. The result of the RPC method call and Call is returned.

func (*CallBuilder) CallForString

func (b *CallBuilder) CallForString(ctx context.Context) (string, error)

CallForString is a convenience method for calling an RPC method that returns a single string. The result of the RPC method call and Call is returned.

func (*CallBuilder) Name

func (b *CallBuilder) Name(methodName string) *CallBuilder

Name sets the name of the method that will be called. This will be appended to any value passed to NamePrefix during Call.

func (*CallBuilder) NamePrefix

func (b *CallBuilder) NamePrefix(methodNamePrefix string) *CallBuilder

NamePrefix sets the prefix of the name of the method that will be called. This will be prepended to method name set by Name during Call.

func (*CallBuilder) Returns

func (b *CallBuilder) Returns(returnPointers ...interface{}) *CallBuilder

Returns sets the return pointers, in order, that will be used to save the return values of the XMLRPC call. Once Call is completed successfully, these objects' values will be updated.

Each passed return pointer must point to a data type that can be unmarshalled from an XMLRPC call response by XMLRpc.

func (*CallBuilder) Timeout

func (b *CallBuilder) Timeout(timeout time.Duration) *CallBuilder

Timeout overrides the default call timeout.

type CommonRPCInterface

type CommonRPCInterface struct {
	XMLRPC                 *XMLRpc
	XMLRPCMethodNamePrefix string
}

CommonRPCInterface is a base implementation of RPCInterface which can be included in structs that wish to implement RPCInterface in a common way with XMLRpc as the XMLRPC client and an optional methodNamePrefix.

func NewCommonRPCInterface

func NewCommonRPCInterface(xmlrpcClient *XMLRpc, methodNamePrefix string) *CommonRPCInterface

NewCommonRPCInterface creates a new instance of CommonRPCInterface.

func (*CommonRPCInterface) Host

func (c *CommonRPCInterface) Host() string

Host returns the host and port of the device this RPC sends requests to.

func (*CommonRPCInterface) RPC

func (c *CommonRPCInterface) RPC(methodName string) *CallBuilder

RPC returns a new CallBuilder instance with the CallBuilder.Name and CallBuilder.NamePrefix already set with methodName and a prefix handled by the implementation, respectively.

Calling this method does not preform a Remote-Procedure-Call itself. The CallBuilder.Call method from the returned CallBuilder instance can be used to do so.

type FaultError

type FaultError struct {
	Code   int
	Reason string

	// Including *errors.E allows FaultError to work with the Tast errors library.
	*errors.E
}

FaultError is a type of error representing an XML-RPC fault.

func NewFaultError

func NewFaultError(code int, reason string) FaultError

NewFaultError creates a FaultError.

type RPCInterface

type RPCInterface interface {
	// RPC returns a new CallBuilder instance with the CallBuilder.Name and
	// CallBuilder.NamePrefix already set with methodName and a prefix handled
	// by the implementation, respectively.
	//
	// Calling this method does not preform a Remote-Procedure-Call itself. The
	// CallBuilder.Call method from the returned CallBuilder instance can be used
	// to do so.
	RPC(methodName string) *CallBuilder

	// Host returns the host and port of the device this RPC sends requests to.
	Host() string
}

RPCInterface is an interface that provides a common way of making RPC calls.

type XMLRpc

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

XMLRpc holds the XML-RPC information.

func New

func New(host string, port int) *XMLRpc

New creates a new XMLRpc object for communicating with XML-RPC server.

func (*XMLRpc) CallBuilder

func (r *XMLRpc) CallBuilder() *CallBuilder

CallBuilder creates a new CallBuilder instance that uses this XMLRpc client.

func (*XMLRpc) Run

func (r *XMLRpc) Run(ctx context.Context, cl Call, out ...interface{}) error

Run makes an XML-RPC call to the server.

Jump to

Keyboard shortcuts

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