Skip to content

Instantly share code, notes, and snippets.

@lionelyoung
Created September 17, 2012 02:53
Show Gist options
  • Save lionelyoung/3735310 to your computer and use it in GitHub Desktop.
Save lionelyoung/3735310 to your computer and use it in GitHub Desktop.
Go XMLRPC Method
func xmlrpc(url string, methodName string, args ...string) string {
// Marshal XML
type Param struct {
Entry string `xml:"value>string"`
}
type methodCall struct {
XMLName xml.Name `xml:"methodCall"`
MethodName string `xml:"methodName"`
Params []Param `xml:"params>param"`
}
v := &methodCall{MethodName: methodName}
v.Params = []Param{}
for _, arg := range args {
v.Params = append(v.Params, Param{arg})
}
b, _ := xml.Marshal(v)
bs := bytes.NewBuffer([]byte(b))
// Deliver Payload
r, e := http.Post(url, "text/xml", bs)
if e != nil {
fmt.Println(e)
return ""
}
defer r.Body.Close()
// Get text of response
body, e := ioutil.ReadAll(r.Body)
if e != nil {
fmt.Println(e)
return ""
}
return string(body)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment