package handlers import ( "context" "golias/models" "html/template" "net/http" ) func HandleCreateRoom(w http.ResponseWriter, r *http.Request) { // parse payload payload := &models.RoomReq{ RoomPass: r.PostFormValue("room_pass"), RoomName: r.PostFormValue("room_name"), } // create a room room, err := createRoom(r.Context(), payload) if err != nil { msg := "failed to create a room" log.Error(msg, "error", err) abortWithError(w, msg) return } ctx := context.WithValue(r.Context(), "current_room", room.ID) ctx, err = updateRoomInSession(ctx, room.ID) if err != nil { msg := "failed to set current room to session" log.Error(msg, "error", err) abortWithError(w, msg) return } // send msg of created room // h.Broker.Notifier <- broker.NotificationEvent{ // EventName: models.MsgRoomListUpdate, // Payload: fmt.Sprintf("%s created a room named %s", r.CreatorName, r.RoomName), // } // return html tmpl, err := template.ParseGlob("components/*.html") if err != nil { abortWithError(w, err.Error()) return } tmpl.ExecuteTemplate(w, "main", nil) }