This commit is contained in:
Deluan
2016-02-25 18:52:07 -05:00
parent a1829d432a
commit e760952263
17 changed files with 40 additions and 59 deletions
-3
View File
@@ -11,6 +11,3 @@ func (c *GetLicenseController) Get() {
response := responses.NewXML(&responses.License{Valid: true})
c.Ctx.Output.Body(response)
}
-3
View File
@@ -20,6 +20,3 @@ func (c *GetMusicFoldersController) Get() {
response := responses.NewXML(musicFolders)
c.Ctx.Output.Body(response)
}
+1 -4
View File
@@ -1,8 +1,8 @@
package api
import (
"github.com/astaxie/beego"
"encoding/xml"
"github.com/astaxie/beego"
"github.com/deluan/gosonic/api/responses"
)
@@ -13,6 +13,3 @@ func (c *PingController) Get() {
xmlBody, _ := xml.Marshal(response)
c.Ctx.Output.Body([]byte(xml.Header + string(xmlBody)))
}
+4 -4
View File
@@ -32,9 +32,9 @@ func init() {
}
type error struct {
XMLName xml.Name`xml:"error"`
Code int `xml:"code,attr"`
Message string `xml:"message,attr"`
XMLName xml.Name `xml:"error"`
Code int `xml:"code,attr"`
Message string `xml:"message,attr"`
}
func NewError(errorCode int) []byte {
@@ -47,4 +47,4 @@ func NewError(errorCode int) []byte {
response.Body = xmlBody
xmlResponse, _ := xml.Marshal(response)
return []byte(xml.Header + string(xmlResponse))
}
}
+2 -2
View File
@@ -4,5 +4,5 @@ import "encoding/xml"
type License struct {
XMLName xml.Name `xml:"license"`
Valid bool `xml:"valid,attr"`
}
Valid bool `xml:"valid,attr"`
}
+4 -4
View File
@@ -4,11 +4,11 @@ import "encoding/xml"
type MusicFolder struct {
XMLName xml.Name `xml:"musicFolder"`
Id string `xml:"id,attr"`
Name string `xml:"name,attr"`
Id string `xml:"id,attr"`
Name string `xml:"name,attr"`
}
type MusicFolders struct {
XMLName xml.Name `xml:"musicFolders"`
XMLName xml.Name `xml:"musicFolders"`
Folders []MusicFolder `xml:"musicFolders"`
}
}
+2 -2
View File
@@ -9,7 +9,7 @@ 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"`
Body []byte `xml:",innerxml"`
}
func NewEmpty() Subsonic {
@@ -22,4 +22,4 @@ func NewXML(body interface{}) []byte {
response.Body = xmlBody
xmlResponse, _ := xml.Marshal(response)
return []byte(xml.Header + string(xmlResponse))
}
}
+4 -4
View File
@@ -19,9 +19,9 @@ func Validate(controller ControllerInterface) {
}
func checkParameters(c ControllerInterface) {
requiredParameters := []string {"u", "p", "v", "c",}
requiredParameters := []string{"u", "p", "v", "c"}
for _,p := range requiredParameters {
for _, p := range requiredParameters {
if c.GetString(p) == "" {
cancel(c, responses.ERROR_MISSING_PARAMETER)
}
@@ -31,11 +31,11 @@ func checkParameters(c ControllerInterface) {
func authenticate(c ControllerInterface) {
user := c.GetString("u")
pass := c.GetString("p") // TODO Handle hex-encoded password
if (user != beego.AppConfig.String("user") || pass != beego.AppConfig.String("password")) {
if user != beego.AppConfig.String("user") || pass != beego.AppConfig.String("password") {
cancel(c, responses.ERROR_AUTHENTICATION_FAIL)
}
}
func cancel(c ControllerInterface, code int) {
c.CustomAbort(200, string(responses.NewError(code)))
}
}