up_switch.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package http
  2. import (
  3. "strconv"
  4. "go-common/library/ecode"
  5. "go-common/library/log"
  6. bm "go-common/library/net/http/blademaster"
  7. )
  8. func switchSet(ctx *bm.Context) {
  9. param := ctx.Request.Form
  10. midStr := param.Get("mid")
  11. fromStr := param.Get("from")
  12. stateStr := param.Get("state")
  13. // check params
  14. mid, err := strconv.ParseInt(midStr, 10, 64)
  15. if err != nil {
  16. log.Error("strconv.ParseInt(%s) error(%v)", midStr, err)
  17. ctx.JSON(nil, ecode.RequestErr)
  18. return
  19. }
  20. if mid <= 0 {
  21. log.Error("switchSet error mid (%d)", mid)
  22. ctx.JSON(nil, ecode.RequestErr)
  23. return
  24. }
  25. from, err := strconv.ParseUint(fromStr, 10, 64)
  26. if err != nil {
  27. log.Error("strconv.ParseInt(%s) error(%v)", fromStr, err)
  28. ctx.JSON(nil, ecode.RequestErr)
  29. return
  30. }
  31. state, err := strconv.Atoi(stateStr)
  32. if err != nil {
  33. log.Error("strconv.ParseInt(%s) error(%v)", stateStr, err)
  34. ctx.JSON(nil, ecode.RequestErr)
  35. return
  36. }
  37. row, err := Svc.SetSwitch(ctx, mid, state, uint8(from))
  38. if err != nil {
  39. ctx.JSON(nil, err)
  40. return
  41. }
  42. ctx.JSON(row, nil)
  43. }
  44. func upSwitch(ctx *bm.Context) {
  45. param := ctx.Request.Form
  46. midStr := param.Get("mid")
  47. fromStr := param.Get("from")
  48. // check params
  49. mid, err := strconv.ParseInt(midStr, 10, 64)
  50. if err != nil {
  51. log.Error("strconv.ParseInt(%s) error(%v)", midStr, err)
  52. ctx.JSON(nil, ecode.RequestErr)
  53. return
  54. }
  55. if mid <= 0 {
  56. log.Error("upSwitch error mid(%d)", mid)
  57. ctx.JSON(nil, ecode.RequestErr)
  58. return
  59. }
  60. from, err := strconv.Atoi(fromStr)
  61. if err != nil {
  62. log.Error("strconv.ParseInt(%s) error(%v)", fromStr, err)
  63. ctx.JSON(nil, ecode.RequestErr)
  64. return
  65. }
  66. state, err := Svc.UpSwitchs(ctx, mid, uint8(from))
  67. if err != nil {
  68. ctx.JSON(nil, err)
  69. return
  70. }
  71. ctx.JSON(map[string]interface{}{
  72. "state": state,
  73. }, nil)
  74. }