up_switch.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package http
  2. import (
  3. "go-common/library/ecode"
  4. "go-common/library/log"
  5. bm "go-common/library/net/http/blademaster"
  6. "go-common/library/net/metadata"
  7. "strconv"
  8. )
  9. func upSwitch(c *bm.Context) {
  10. ip := metadata.String(c, metadata.RemoteIP)
  11. // check user
  12. midI, ok := c.Get("mid")
  13. if !ok {
  14. c.JSON(nil, ecode.NoLogin)
  15. return
  16. }
  17. mid, _ := midI.(int64)
  18. rs, err := upSvc.UpSwitch(c, mid, ip)
  19. if err != nil {
  20. c.JSON(nil, err)
  21. return
  22. }
  23. rs.Show = 1 //播放开关全量
  24. c.JSON(rs, nil)
  25. }
  26. func setUpSwitch(c *bm.Context) {
  27. ip := metadata.String(c, metadata.RemoteIP)
  28. params := c.Request.Form
  29. stateStr := params.Get("state")
  30. fromStr := params.Get("from")
  31. midI, ok := c.Get("mid")
  32. if !ok {
  33. c.JSON(nil, ecode.NoLogin)
  34. return
  35. }
  36. state, err := strconv.Atoi(stateStr)
  37. if err != nil {
  38. log.Error("strconv.Atoi(%s) error(%v)", stateStr, err)
  39. c.JSON(nil, ecode.RequestErr)
  40. return
  41. }
  42. from, err := strconv.Atoi(fromStr)
  43. if err != nil {
  44. log.Error("strconv.Atoi(%s) error(%v)", fromStr, err)
  45. c.JSON(nil, ecode.RequestErr)
  46. return
  47. }
  48. mid, _ := midI.(int64)
  49. id, err := upSvc.SetUpSwitch(c, mid, state, from, ip)
  50. if err != nil {
  51. c.JSON(nil, err)
  52. return
  53. }
  54. c.JSON(map[string]interface{}{
  55. "id": id,
  56. }, nil)
  57. }