handlers.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package remdesaux
  2. import (
  3. "encoding/json"
  4. "net/http"
  5. )
  6. // Handler for switching USB to KVM side
  7. func (c *AuxMcu) HandleSwitchUSBToKVM(w http.ResponseWriter, r *http.Request) {
  8. if err := c.SwitchUSBToKVM(); err != nil {
  9. http.Error(w, err.Error(), http.StatusInternalServerError)
  10. return
  11. }
  12. w.WriteHeader(http.StatusOK)
  13. }
  14. // Handler for switching USB to Remote side
  15. func (c *AuxMcu) HandleSwitchUSBToRemote(w http.ResponseWriter, r *http.Request) {
  16. if err := c.SwitchUSBToRemote(); err != nil {
  17. http.Error(w, err.Error(), http.StatusInternalServerError)
  18. return
  19. }
  20. w.WriteHeader(http.StatusOK)
  21. }
  22. // Handler for pressing the power button
  23. func (c *AuxMcu) HandlePressPowerButton(w http.ResponseWriter, r *http.Request) {
  24. if err := c.PressPowerButton(); err != nil {
  25. http.Error(w, err.Error(), http.StatusInternalServerError)
  26. return
  27. }
  28. w.WriteHeader(http.StatusOK)
  29. }
  30. // Handler for releasing the power button
  31. func (c *AuxMcu) HandleReleasePowerButton(w http.ResponseWriter, r *http.Request) {
  32. if err := c.ReleasePowerButton(); err != nil {
  33. http.Error(w, err.Error(), http.StatusInternalServerError)
  34. return
  35. }
  36. w.WriteHeader(http.StatusOK)
  37. }
  38. // Handler for pressing the reset button
  39. func (c *AuxMcu) HandlePressResetButton(w http.ResponseWriter, r *http.Request) {
  40. if err := c.PressResetButton(); err != nil {
  41. http.Error(w, err.Error(), http.StatusInternalServerError)
  42. return
  43. }
  44. w.WriteHeader(http.StatusOK)
  45. }
  46. // Handler for releasing the reset button
  47. func (c *AuxMcu) HandleReleaseResetButton(w http.ResponseWriter, r *http.Request) {
  48. if err := c.ReleaseResetButton(); err != nil {
  49. http.Error(w, err.Error(), http.StatusInternalServerError)
  50. return
  51. }
  52. w.WriteHeader(http.StatusOK)
  53. }
  54. // Handler for getting the UUID
  55. func (c *AuxMcu) HandleGetUUID(w http.ResponseWriter, r *http.Request) {
  56. uuid, err := c.GetUUID()
  57. if err != nil {
  58. http.Error(w, err.Error(), http.StatusInternalServerError)
  59. return
  60. }
  61. w.Header().Set("Content-Type", "application/json")
  62. json.NewEncoder(w).Encode(map[string]string{"uuid": uuid})
  63. }
  64. // Handler for getting the USB mass storage side
  65. func (c *AuxMcu) HandleGetUSBMassStorageSide(w http.ResponseWriter, r *http.Request) {
  66. side := c.GetUSBMassStorageSide()
  67. w.Header().Set("Content-Type", "application/json")
  68. json.NewEncoder(w).Encode(map[string]interface{}{"usb_mass_storage_side": side})
  69. }