clear-retweet.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package http
  2. import (
  3. "encoding/json"
  4. "go-common/library/ecode"
  5. bm "go-common/library/net/http/blademaster"
  6. "io/ioutil"
  7. )
  8. // clearStreamStatus 清理互推标志
  9. func clearStreamStatus(c *bm.Context) {
  10. type room struct {
  11. RoomID json.Number `json:"room_id"`
  12. }
  13. vp := &room{}
  14. switch c.Request.Header.Get("Content-Type") {
  15. case "application/x-www-form-urlencoded":
  16. if len(c.Request.PostForm) == 0 {
  17. c.Set("output_data", "clearStreamStatus = empty post body")
  18. c.JSONMap(map[string]interface{}{"message": "empty post body"}, ecode.RequestErr)
  19. c.Abort()
  20. return
  21. }
  22. vp.RoomID = json.Number(c.Request.PostFormValue("room_id"))
  23. default:
  24. defer c.Request.Body.Close()
  25. b, err := ioutil.ReadAll(c.Request.Body)
  26. if err != nil {
  27. c.Set("output_data", err.Error())
  28. c.JSONMap(map[string]interface{}{"message": err.Error()}, ecode.RequestErr)
  29. c.Abort()
  30. return
  31. }
  32. if len(b) == 0 {
  33. c.Set("output_data", "clearStreamStatus empty params")
  34. c.JSONMap(map[string]interface{}{"message": "empty params"}, ecode.RequestErr)
  35. c.Abort()
  36. return
  37. }
  38. err = json.Unmarshal(b, &vp)
  39. if err != nil {
  40. c.Set("output_data", "room_id is not right")
  41. c.JSONMap(map[string]interface{}{"message": "room_id is not right"}, ecode.RequestErr)
  42. c.Abort()
  43. return
  44. }
  45. }
  46. roomID, err := vp.RoomID.Int64()
  47. if roomID <= 0 || err != nil {
  48. c.Set("output_data", "room_id is not right")
  49. c.JSONMap(map[string]interface{}{"message": "room_id is not right"}, ecode.RequestErr)
  50. c.Abort()
  51. return
  52. }
  53. c.Set("input_params", map[string]int64{"room_id": roomID})
  54. err = srv.ClearStreamStatus(c, roomID)
  55. if err != nil {
  56. c.Set("output_data", err.Error())
  57. c.JSONMap(map[string]interface{}{"message": err.Error()}, ecode.RequestErr)
  58. c.Abort()
  59. return
  60. }
  61. c.Set("output_data", "clear status success")
  62. c.JSONMap(map[string]interface{}{"message": "ok"}, nil)
  63. }