diff options
| author | Shulhan <ms@kilabit.info> | 2021-05-19 13:41:13 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2021-05-19 13:41:13 +0700 |
| commit | bd51133fbda340542ec29ec1035b028ea112e028 (patch) | |
| tree | 0e1c63bec6a061baafddc2edcd710ab2d291f157 /lib/xmlrpc/response.go | |
| parent | 0f2059b07661265439a20d895a7a4481ef12b4c8 (diff) | |
| download | pakakeh.go-bd51133fbda340542ec29ec1035b028ea112e028.tar.xz | |
xmlrpc: add method to marshal Response
Diffstat (limited to 'lib/xmlrpc/response.go')
| -rw-r--r-- | lib/xmlrpc/response.go | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/xmlrpc/response.go b/lib/xmlrpc/response.go index 1e0343de..53d35a1f 100644 --- a/lib/xmlrpc/response.go +++ b/lib/xmlrpc/response.go @@ -17,6 +17,32 @@ type Response struct { IsFault bool } +// +// MarshalText encode the Response instance into XML text. +// +func (resp *Response) MarshalText() (out []byte, err error) { + var buf bytes.Buffer + + buf.WriteString(xml.Header) + buf.WriteString("<methodResponse>") + + if !resp.IsFault { + fmt.Fprintf(&buf, "<params><param>%s</param></params>", + resp.Param) + } else { + buf.WriteString("<fault><value><struct>") + fmt.Fprintf(&buf, "<member><name>faultCode</name><value><int>%d</int></value></member>", + resp.FaultCode) + fmt.Fprintf(&buf, "<member><name>faultString</name><value><string>%s</string></value></member>", + resp.FaultMessage) + buf.WriteString("</struct></value></fault>") + } + + buf.WriteString("</methodResponse>") + + return buf.Bytes(), nil +} + func (resp *Response) UnmarshalText(text []byte) (err error) { var ( logp = "xmlrpc: Response" |
