Skip to content

Instantly share code, notes, and snippets.

@mbeale
Created May 19, 2012 19:28
Show Gist options
  • Save mbeale/2732090 to your computer and use it in GitHub Desktop.
Save mbeale/2732090 to your computer and use it in GitHub Desktop.
GO and XML sample4
//Generic Reader
type nopCloser struct {
io.Reader
}
//update function
func (a *Account) Update() error {
if xmlstring, err := xml.MarshalIndent(a, "", " "); err == nil {
xmlstring = []byte(xml.Header + string(xmlstring))
client := &http.Client{}
body := nopCloser{bytes.NewBufferString(string(xmlstring))}
if req, err := http.NewRequest("PUT", "http://example.com/someresource", body); err != nil {
return err
} else {
req.Header.Add("Accept", "application/xml")
req.Header.Add("Content-Type","application/xml; charset=utf-8")
req.ContentLength = int64(len(string(msgbody)))
if resp, resperr := client.Do(req); resperr != nil {
return resperr
}
}
} else {
return err
}
return nil
}
func main() {
account, _ = GetAccount("account_code_here")
account.FirstName = "Santa"
account.LastName = "Claus"
if err := account.Update(); err == nil {
println("Successfully Updated")
} else {
println(err.Error())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment