Refactored responses

This commit is contained in:
Deluan
2016-03-02 11:11:46 -05:00
parent 77e3aa7620
commit 01c68d6802
9 changed files with 64 additions and 69 deletions
+3 -13
View File
@@ -5,21 +5,11 @@ import (
"github.com/astaxie/beego"
)
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 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))
func ToXML(response Subsonic) []byte {
xmlBody, _ := xml.Marshal(response)
return []byte(xml.Header + string(xmlBody))
}