diff --git a/controllers/get_license.go b/controllers/get_license.go index 95eb938ba..cce7d8be9 100644 --- a/controllers/get_license.go +++ b/controllers/get_license.go @@ -2,7 +2,6 @@ package controllers import ( "github.com/astaxie/beego" - "encoding/xml" "github.com/deluan/gosonic/responses" ) @@ -10,9 +9,8 @@ type GetLicenseController struct{ beego.Controller } // @router /rest/getLicense.view [get] func (this *GetLicenseController) Get() { - response := responses.NewGetLicense(true) - xmlBody, _ := xml.Marshal(response) - this.Ctx.Output.Body([]byte(xml.Header + string(xmlBody))) + response := responses.NewXML(&responses.License{Valid: true}) + this.Ctx.Output.Body(response) } diff --git a/controllers/ping.go b/controllers/ping.go index 2ab2765ee..4af00246b 100644 --- a/controllers/ping.go +++ b/controllers/ping.go @@ -10,7 +10,7 @@ type PingController struct{ beego.Controller } // @router /rest/ping.view [get] func (this *PingController) Get() { - response := responses.NewSubsonic() + response := responses.NewEmpty() xmlBody, _ := xml.Marshal(response) this.Ctx.Output.Body([]byte(xml.Header + string(xmlBody))) } diff --git a/responses/license.go b/responses/license.go index 7b544517f..f8d125e57 100644 --- a/responses/license.go +++ b/responses/license.go @@ -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 -} +} \ No newline at end of file diff --git a/responses/subsonic.go b/responses/subsonic.go index 84723ad6e..4ea5a2c04 100644 --- a/responses/subsonic.go +++ b/responses/subsonic.go @@ -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)) } \ No newline at end of file