Esempio n. 1
0
// Return a list of albums or a specific album
func (h ControlHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	controls, err := player.NewMpdControls(h.conf)
	defer controls.Close()
	switch r.Method {
	case "GET":
		log.Printf("GET: return current status\n")
		err = h.currentStatus(w, controls)
	case "POST":
		err = h.command(w, r, controls)
	}

	if err != nil {
		log.Printf("Error detected in /control: %s\n", err)
		http.Error(w, err.Error(), http.StatusInternalServerError)
	}
}
Esempio n. 2
0
// Return a list of albums or a specific album
func (h PlaylistHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	controls, err := player.NewMpdControls(h.conf)
	defer controls.Close()
	playlist := player.NewMpdPlaylist(h.conf)
	defer playlist.Close()

	switch r.Method {
	case "GET":
		log.Printf("GET: Showing current playlist\n")
		err = h.currentPlaylist(w, playlist)
	case "POST":
		err = h.command(w, r, playlist, controls)
	}

	if err != nil {
		log.Printf("Error detected in /playlist: %s", err)
		http.Error(w, err.Error(), http.StatusInternalServerError)
	}
}