Game list should now be sorted, a new endpoint with the game list in random order have been added.
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
var currentSong = -1
|
||||
@@ -161,6 +162,20 @@ func getAllGames() []string {
|
||||
return jsonArray
|
||||
}
|
||||
|
||||
func getAllGamesRandom() []string {
|
||||
if games == nil || len(games) == 0 {
|
||||
games = findAllGames()
|
||||
}
|
||||
|
||||
var jsonArray []string
|
||||
for _, game := range games {
|
||||
jsonArray = append(jsonArray, game.gameName)
|
||||
}
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
rand.Shuffle(len(jsonArray), func(i, j int) { jsonArray[i], jsonArray[j] = jsonArray[j], jsonArray[i] })
|
||||
return jsonArray
|
||||
}
|
||||
|
||||
func setPlayed(songNumber int) {
|
||||
if songQue == nil || len(songQue) == 0 || songNumber >= len(songQue) {
|
||||
return
|
||||
@@ -248,6 +263,10 @@ func musicHandler(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
_ = json.NewEncoder(w).Encode(getAllGames())
|
||||
|
||||
} else if r.URL.Path == "/music/all/random" && r.Method == http.MethodGet {
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
_ = json.NewEncoder(w).Encode(getAllGamesRandom())
|
||||
|
||||
} else if r.URL.Path == "/music/played" && r.Method == http.MethodPut {
|
||||
var p Played
|
||||
err := json.NewDecoder(r.Body).Decode(&p)
|
||||
|
||||
Reference in New Issue
Block a user