Changed the structure of the whole application, should be no changes to functionality.
This commit is contained in:
28
pkg/api/sync.go
Normal file
28
pkg/api/sync.go
Normal 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user