ws-refactor #3

Merged
whysman merged 4 commits from ws-refactor into master 2025-02-26 17:00:28 +00:00
Showing only changes of commit 0eee8e006d - Show all commits

View File

@ -234,7 +234,6 @@ func fetchAllRecords() (map[string]string, error) {
return records, nil
}
/*
func getState(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
http.Error(w, "Only POST method is allowed", http.StatusMethodNotAllowed)
@ -251,7 +250,7 @@ func fetchAllRecords() (map[string]string, error) {
http.Error(w, "Invalid JSON format", http.StatusBadRequest)
return
}
fmt.Println(request)
if request.Id == "" {
fmt.Println("Missing or empty Id field")
http.Error(w, "Missing or empty Id field", http.StatusBadRequest)
@ -287,7 +286,7 @@ func fetchAllRecords() (map[string]string, error) {
http.Error(w, "Failed to encode response", http.StatusInternalServerError)
}
}
*/
func setState(w http.ResponseWriter, r *http.Request, s *Server) {
if r.Method != http.MethodPost {
http.Error(w, "Only POST method is allowed", http.StatusMethodNotAllowed)
@ -385,7 +384,7 @@ func main() {
// Register routes on the mux router
router.HandleFunc("/ws", server.handleConnections).Methods("GET")
//router.HandleFunc("/get", getState).Methods("POST")
router.HandleFunc("/get", getState).Methods("POST")
router.HandleFunc("/set", func(w http.ResponseWriter, r *http.Request) {
setState(w, r, server)
}).Methods("POST")