Refactored responses again

This commit is contained in:
Deluan
2016-02-24 12:00:55 -05:00
parent 1a3f370ea6
commit c6dfea51ff
4 changed files with 18 additions and 20 deletions
+10 -1
View File
@@ -9,8 +9,17 @@ type Subsonic struct {
XMLName xml.Name `xml:"http://subsonic.org/restapi subsonic-response"`
Status string `xml:"status,attr"`
Version string `xml:"version,attr"`
Body []byte `xml:",innerxml"`
}
func NewSubsonic() Subsonic {
func NewEmpty() Subsonic {
return Subsonic{Status: "ok", Version: beego.AppConfig.String("apiversion")}
}
func NewXML(body interface{}) []byte {
response := NewEmpty()
xmlBody, _ := xml.Marshal(body)
response.Body = xmlBody
xmlResponse, _ := xml.Marshal(response)
return []byte(xml.Header + string(xmlResponse))
}