dnscontrol/vendor/github.com/renier/xmlrpc/response.go
Jamie Lennox 7daa7a6467 Add SoftLayer DNS provider (#59)
Add SoftLayer DNS as a DomainServiceProvider.

The SoftLayer API is a bit of a mess and treats MX and SRV records
differently. This leads to some replication and custom handling issues
to work around.

In this patch I have to change the SRV test case to be _tcp instead of
_protocol because softlayer requires a "known" protocol which AFAICT is
tcp, udp or tls. I think this will be acceptable in most cases.

Signed-off-by: Jamie Lennox <jamielennox@gmail.com>
2017-09-26 13:14:53 -04:00

57 lines
974 B
Go

package xmlrpc
import (
"regexp"
)
var (
faultRx = regexp.MustCompile(`<fault>(\s|\S)+</fault>`)
)
type failedResponse struct {
Code interface{} `xmlrpc:"faultCode"`
Error string `xmlrpc:"faultString"`
HttpStatusCode int
}
func (r *failedResponse) err() error {
return &XmlRpcError{
Code: r.Code,
Err: r.Error,
HttpStatusCode: r.HttpStatusCode,
}
}
type Response struct {
data []byte
httpStatusCode int
}
func NewResponse(data []byte, httpStatusCode int) *Response {
return &Response{
data: data,
httpStatusCode: httpStatusCode,
}
}
func (r *Response) Failed() bool {
return faultRx.Match(r.data)
}
func (r *Response) Err() error {
failedResp := new(failedResponse)
if err := unmarshal(r.data, failedResp); err != nil {
return err
}
failedResp.HttpStatusCode = r.httpStatusCode
return failedResp.err()
}
func (r *Response) Unmarshal(v interface{}) error {
if err := unmarshal(r.data, v); err != nil {
return err
}
return nil
}