aboutsummaryrefslogtreecommitdiffstats
path: root/modern.go
diff options
context:
space:
mode:
Diffstat (limited to 'modern.go')
-rw-r--r--modern.go19
1 files changed, 12 insertions, 7 deletions
diff --git a/modern.go b/modern.go
index 946335d..9106123 100644
--- a/modern.go
+++ b/modern.go
@@ -27,6 +27,12 @@ type Token struct {
string
}
+type LFMResponse struct {
+ XMLName xml.Name `xml:"lfm" json:"-"`
+ Status string `xml:"status,attr" json:"-"`
+ Response ApiResponse `json:"scrobbles"`
+}
+
type Attrs struct {
Accepted int `xml:"accepted,attr" json:"accepted"`
Ignored int `xml:"ignored,attr" json:"ignored"`
@@ -49,8 +55,7 @@ func (field Correctable) Value() (driver.Value, error) {
func NewCorrectable(name string) Correctable {
return Correctable{
- Corrected: 0,
- Name: name,
+ Name: name,
}
}
@@ -98,20 +103,19 @@ func (store *SqlStore) TrackScrobble(r *http.Request) (ApiResponse, error) {
func ApiHandler(ds DataStore, w http.ResponseWriter, r *http.Request) {
method := r.FormValue("method")
- var response ApiResponse
+ response := LFMResponse{Status: "ok"}
switch method {
case "auth.getToken":
- response = ds.AuthGetToken(r)
+ response.Response = ds.AuthGetToken(r)
case "auth.getSession":
- response = ds.AuthGetSession(r)
+ response.Response = ds.AuthGetSession(r)
case "track.scrobble":
if r, err := ds.TrackScrobble(r); err != nil {
fmt.Printf("%v\n", err)
} else {
- response = r
+ response.Response = r
}
}
-
var text []byte
switch r.FormValue("format") {
case "json":
@@ -120,5 +124,6 @@ func ApiHandler(ds DataStore, w http.ResponseWriter, r *http.Request) {
text, _ = xml.Marshal(response)
}
fmt.Printf("%s\n", text)
+ fmt.Fprint(w, xml.Header)
w.Write(text)
}