mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2025-01-13 02:50:27 +08:00
7daa7a6467
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>
57 lines
1.1 KiB
Go
57 lines
1.1 KiB
Go
package xmlrpc
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"net/http"
|
|
)
|
|
|
|
func NewRequest(url string, method string, args interface{}) (*http.Request, error) {
|
|
var t []interface{}
|
|
var ok bool
|
|
if t, ok = args.([]interface{}); !ok {
|
|
if args != nil {
|
|
t = []interface{}{args}
|
|
}
|
|
}
|
|
|
|
body, err := EncodeMethodCall(method, t...)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
request, err := http.NewRequest("POST", url, bytes.NewReader(body))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
request.Header.Set("Content-Type", "text/xml")
|
|
request.Header.Set("Content-Length", fmt.Sprintf("%d", len(body)))
|
|
|
|
return request, nil
|
|
}
|
|
|
|
func EncodeMethodCall(method string, args ...interface{}) ([]byte, error) {
|
|
var b bytes.Buffer
|
|
b.WriteString(`<?xml version="1.0" encoding="UTF-8"?>`)
|
|
b.WriteString(fmt.Sprintf("<methodCall><methodName>%s</methodName>", method))
|
|
|
|
if args != nil {
|
|
b.WriteString("<params>")
|
|
|
|
for _, arg := range args {
|
|
p, err := marshal(arg)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
b.WriteString(fmt.Sprintf("<param>%s</param>", string(p)))
|
|
}
|
|
|
|
b.WriteString("</params>")
|
|
}
|
|
|
|
b.WriteString("</methodCall>")
|
|
|
|
return b.Bytes(), nil
|
|
}
|