Added /addQue to add the last received song to the songQue. Changed /rand and /rand/low to not add song to the que. Changed /next to not call /rand when the end of the que is reached, instead the last song in the que will be resent.
This commit is contained in:
91
indexFacade.go
Normal file
91
indexFacade.go
Normal file
@@ -0,0 +1,91 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
func indexHandler(w http.ResponseWriter, r *http.Request) {
|
||||
setCorsAndNoCacheHeaders(&w, r)
|
||||
|
||||
if r.URL.Path == "/version" {
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
|
||||
testf()
|
||||
|
||||
data := VersionData{Version: "2.1.0",
|
||||
Changelog: "Added /addQue to add the last received song to the songQue. " +
|
||||
"Changed /rand and /rand/low to not add song to the que. " +
|
||||
"Changed /next to not call /rand when the end of the que is reached, instead the last song in the que will be resent.",
|
||||
History: []VersionData{
|
||||
{
|
||||
Version: "2.0.3",
|
||||
Changelog: "Another small change that should fix the caching problem.",
|
||||
},
|
||||
{
|
||||
Version: "2.0.2",
|
||||
Changelog: "Hopefully fixed the caching problem with random.",
|
||||
},
|
||||
{
|
||||
Version: "2.0.1",
|
||||
Changelog: "Fixed CORS",
|
||||
},
|
||||
{
|
||||
Version: "2.0.0",
|
||||
Changelog: "Rebuilt the application in Go.",
|
||||
},
|
||||
{
|
||||
Version: "1.2.0",
|
||||
Changelog: "Made the /sync endpoint async. " +
|
||||
"Fixed bug where the game list wasn't reloaded when using /reset. " +
|
||||
"Fixed bug where the songNo showed in the list didn't match what should be sent.",
|
||||
},
|
||||
{
|
||||
Version: "1.1.0",
|
||||
Changelog: "Added sync endpoint, don't really trust it to 100%, would say beta. " +
|
||||
"Fixed bug with /next after /previous. Added /reset endpoint. " +
|
||||
"Added some info more to /info and /list.",
|
||||
},
|
||||
{
|
||||
Version: "1.0.0",
|
||||
Changelog: "Added swagger documentation. Created version 1.0.",
|
||||
},
|
||||
{
|
||||
Version: "0.5.5",
|
||||
Changelog: "Added increase played endpoint.",
|
||||
},
|
||||
},
|
||||
}
|
||||
_ = json.NewEncoder(w).Encode(data)
|
||||
|
||||
} else if r.URL.Path == "/doc" {
|
||||
http.ServeFile(w, r, "./doc/swagger.yaml")
|
||||
|
||||
} else if r.URL.Path == "/" {
|
||||
rows, dbErr := dbPool.Query(context.Background(), "select game_name from game")
|
||||
if dbErr != nil {
|
||||
_, _ = fmt.Fprintf(os.Stderr, "QueryRow failed: %v\n", dbErr)
|
||||
os.Exit(1)
|
||||
}
|
||||
for rows.Next() {
|
||||
var gameName string
|
||||
dbErr = rows.Scan(&gameName)
|
||||
if dbErr != nil {
|
||||
_, _ = fmt.Fprintf(os.Stderr, "QueryRow failed: %v\n", dbErr)
|
||||
}
|
||||
_, _ = fmt.Fprintf(w, "%v\n", gameName)
|
||||
}
|
||||
|
||||
_, err := fmt.Fprint(w, "Hello, World!!")
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
}
|
||||
} else {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user