handlers.go 834 B

123456789101112131415161718192021222324252627282930
  1. package main
  2. import (
  3. "encoding/json"
  4. "net/http"
  5. )
  6. type Status struct {
  7. Playing bool //If the device is playing
  8. PlayingFileName string //The playing filename
  9. PlayingFileURL string //The playing URL
  10. PlayingPosition int //The number of seconds that is currently playing
  11. Volume int //The volume currently is playing at, in percentage
  12. Status string //Status of the device, support {downloading, converting, playing, paused, ready}
  13. }
  14. func handleIndex(w http.ResponseWriter, r *http.Request) {
  15. //Serve the index
  16. sendOK(w)
  17. }
  18. func handleStatus(w http.ResponseWriter, r *http.Request) {
  19. //Send out the current device status
  20. js, _ := json.Marshal(deviceStatus)
  21. sendJSONResponse(w, string(js))
  22. }
  23. func handleEndpoints(w http.ResponseWriter, r *http.Request) {
  24. }