quintodrome/controllers/responses/subsonic.go

25 lines
606 B
Go
Raw Normal View History

package responses
import (
"encoding/xml"
"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"`
2016-02-24 08:00:55 -09:00
Body []byte `xml:",innerxml"`
}
2016-02-24 08:00:55 -09:00
func NewEmpty() Subsonic {
return Subsonic{Status: "ok", Version: beego.AppConfig.String("apiVersion")}
2016-02-24 08:00:55 -09:00
}
func NewXML(body interface{}) []byte {
response := NewEmpty()
xmlBody, _ := xml.Marshal(body)
response.Body = xmlBody
xmlResponse, _ := xml.Marshal(response)
return []byte(xml.Header + string(xmlResponse))
}