Changed the structure of the whole application, should be no changes to functionality.

This commit is contained in:
2021-12-05 11:18:48 +01:00
parent 0a73134381
commit e1de6f0f76
28 changed files with 935 additions and 1105 deletions

28
pkg/api/sync.go Normal file
View File

@@ -0,0 +1,28 @@
package api
import (
"fmt"
"music-server/pkg/helpers"
"music-server/pkg/server"
"net/http"
)
func SyncHandler(w http.ResponseWriter, r *http.Request) {
helpers.SetCorsAndNoCacheHeaders(&w, r)
if r.URL.Path == "/sync" {
w.Header().Add("Content-Type", "application/json")
server.SyncGames()
_, err := fmt.Fprint(w, "Games are synced")
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
}
} else if r.URL.Path == "/sync/reset" {
w.Header().Add("Content-Type", "application/json")
server.ResetDB()
_, err := fmt.Fprint(w, "Games and songs are deleted from the database")
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
}
}
}