package xmlrpc
import "git.sr.ht/~shulhan/pakakeh.go/lib/xmlrpc"
Package xmlrpc provide an implementation of XML-RPC specification, http://xmlrpc.com/spec.md.
Index ¶
- type Client
- func NewClient(url *url.URL, timeout time.Duration) (client *Client, err error)
- func (cl *Client) Close()
- func (cl *Client) Send(req Request) (resp Response, err error)
- type Kind
- type Request
- func NewRequest(methodName string, params []any) (req Request, err error)
- func (req Request) MarshalText() (out []byte, err error)
- func (req *Request) UnmarshalText(text []byte) (err error)
- type Response
- func (resp *Response) MarshalText() (out []byte, err error)
- func (resp *Response) UnmarshalText(text []byte) (err error)
- func (resp *Response) Unwrap() (err error)
- type Value
Examples ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client for XML-RPC.
func NewClient ¶
NewClient create and initialize new connection to RPC server.
func (*Client) Close ¶
func (cl *Client) Close()
Close the client connection.
func (*Client) Send ¶
Send the RPC method with parameters to the server.
type Kind ¶
type Kind int
Kind define the known type in Value.
This is looks like the reflect.Kind but limited only to specific types defined in XML-RPC.
const ( Unset Kind = iota String // represent Go string type. Boolean // represent Go bool type. Integer // represent Go int8, int16, int32, uint8, and uint16 types. Double // represent Go uint32, uint64, float32, and float64 types. DateTime // represent Go time.Time type. Base64 // represent Go string type. Struct // represent Go struct type. Array // represent Go array and slice types. )
List of available Kind.
type Request ¶
Request represent the XML-RPC request, including method name and optional parameters.
func NewRequest ¶
NewRequest create and initialize new request.
func (Request) MarshalText ¶
MarshalText implement the encoding.TextMarshaler interface.
func (*Request) UnmarshalText ¶
UnmarshalText parse the XML request.
type Response ¶
Response contains the XML-RPC response.
func (*Response) MarshalText ¶
MarshalText encode the Response instance into XML text.
func (*Response) UnmarshalText ¶
UnmarshalText convert the XML text into Response.
func (*Response) Unwrap ¶
Unwrap return the error as instance of *liberror.E.
type Value ¶
type Value struct { // In contains scalar value for Base64, Boolean, Double, Integer, // String, and DateTime. // It would be nil for Kind of Array and Struct. In any // Pair of struct member name and its value. StructMembers map[string]*Value // List of array values. ArrayValues []*Value Kind Kind }
Value represent dynamic value of XML-RPC type.
func NewValue ¶
NewValue convert Go type data into XML-RPC value.
func (*Value) GetFieldAsBoolean ¶
GetFieldAsBoolean get the struct's field value by its key as boolean.
Code:
Output:Example¶
{
var (
xmlb = `<?xml version="1.0"?>
<methodResponse>
<params>
<param>
<value>
<struct>
<member>
<name>boolean_false</name>
<value><boolean>0</boolean></value>
</member>
<member>
<name>boolean_true</name>
<value><boolean>1</boolean></value>
</member>
<member>
<name>string_0</name>
<value><string>0</string></value>
</member>
<member>
<name>string_1</name>
<value><string>1</string></value>
</member>
</struct>
</value>
</param>
</params>
</methodResponse>
`
res = &Response{}
err error
)
err = res.UnmarshalText([]byte(xmlb))
if err != nil {
log.Fatal(err)
}
fmt.Println("Get boolean field as string:")
fmt.Println(res.Param.GetFieldAsString("boolean_false"))
fmt.Println(res.Param.GetFieldAsString("boolean_true"))
fmt.Println("Get boolean field as boolean:")
fmt.Println(res.Param.GetFieldAsBoolean("boolean_false"))
fmt.Println(res.Param.GetFieldAsBoolean("boolean_true"))
fmt.Println("Get string field as boolean:")
fmt.Println(res.Param.GetFieldAsBoolean("string_0"))
fmt.Println(res.Param.GetFieldAsBoolean("string_1"))
// Output:
// Get boolean field as string:
// false
// true
// Get boolean field as boolean:
// false
// true
// Get string field as boolean:
// false
// false
}
Get boolean field as string:
false
true
Get boolean field as boolean:
false
true
Get string field as boolean:
false
false
func (*Value) GetFieldAsFloat ¶
GetFieldAsFloat get struct's field value by name as float64.
func (*Value) GetFieldAsInteger ¶
GetFieldAsInteger get struct's field value by name as int.
func (*Value) GetFieldAsString ¶
GetFieldAsString get struct's field value by name as string.
func (*Value) String ¶
Source Files ¶
client.go request.go response.go value.go xml.go xmlrpc.go
- Version
- v0.60.0 (latest)
- Published
- Feb 1, 2025
- Platform
- linux/amd64
- Imports
- 14 packages
- Last checked
- 25 minutes ago –
Tools for package owners.