Refactored responses again
This commit is contained in:
+5
-14
@@ -1,17 +1,8 @@
|
||||
package responses
|
||||
|
||||
type valid struct {
|
||||
import "encoding/xml"
|
||||
|
||||
type License struct {
|
||||
XMLName xml.Name `xml:"license"`
|
||||
Valid bool `xml:"valid,attr"`
|
||||
}
|
||||
|
||||
type license struct {
|
||||
Subsonic
|
||||
Body valid `xml:"license"`
|
||||
}
|
||||
|
||||
func NewGetLicense(valid bool) *license {
|
||||
response := new(license)
|
||||
response.Subsonic = NewSubsonic()
|
||||
response.Body.Valid = valid
|
||||
return response
|
||||
}
|
||||
}
|
||||
+10
-1
@@ -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))
|
||||
}
|
||||
Reference in New Issue
Block a user