12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- package main
- import (
- "encoding/json"
- "net/http"
- )
- type Status struct {
- Playing bool //If the device is playing
- PlayingFileName string //The playing filename
- PlayingFileURL string //The playing URL
- PlayingPosition int //The number of seconds that is currently playing
- Volume int //The volume currently is playing at, in percentage
- Status string //Status of the device, support {downloading, converting, playing, paused, ready}
- }
- type Endpoint struct {
- Name string
- RelPath string
- Desc string
- Type string
- AllowRead bool
- AllowWrite bool
- Min int
- Max int
- Steps float64
- Regex string
- }
- func handleIndex(w http.ResponseWriter, r *http.Request) {
- //Serve the index
- sendOK(w)
- }
- func handleStatus(w http.ResponseWriter, r *http.Request) {
- //Send out the current device status
- js, _ := json.Marshal(deviceStatus)
- sendJSONResponse(w, string(js))
- }
- func handleEndpoints(w http.ResponseWriter, r *http.Request) {
- endpoints := []Endpoint{}
- endpoints = append(endpoints, Endpoint{
- Name: "Play",
- RelPath: "play",
- Desc: "Toggle player to play or pause",
- Type: "none",
- })
- endpoints = append(endpoints, Endpoint{
- Name: "Stop",
- RelPath: "stop",
- Desc: "Stop and flush the buffer of the playing song",
- Type: "none",
- })
- endpoints = append(endpoints, Endpoint{
- Name: "Load",
- RelPath: "load",
- Desc: "Load a network resources to play",
- Type: "string",
- })
- endpoints = append(endpoints, Endpoint{
- Name: "Volume",
- RelPath: "vol",
- Desc: "Set the volume of the device playback in percentage",
- Type: "integer",
- Max: 100,
- Min: 0,
- Steps: 1,
- })
- endpoints = append(endpoints, Endpoint{
- Name: "Jump",
- RelPath: "jump",
- Desc: "Jump to a given location on the track",
- Type: "integer",
- Steps: 1,
- })
- js, _ := json.Marshal(endpoints)
- sendJSONResponse(w, string(js))
- }
|