push.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package http
  2. import (
  3. "go-common/library/ecode"
  4. bm "go-common/library/net/http/blademaster"
  5. )
  6. const maxMsgSize = 1024 * 1024 * 8
  7. func pushKeys(c *bm.Context) {
  8. v := new(struct {
  9. Op int32 `form:"operation" validate:"required"`
  10. Keys []string `form:"keys,split" validate:"required"`
  11. Msg string `form:"message" validate:"required"`
  12. ContentType int32 `form:"content_type"`
  13. })
  14. if err := c.Bind(v); err != nil {
  15. return
  16. }
  17. if len(v.Msg) > maxMsgSize {
  18. c.JSON(ecode.FileTooLarge, nil)
  19. }
  20. c.JSON(nil, srv.PushKeys(c, v.Op, v.Keys, v.Msg, v.ContentType))
  21. }
  22. func pushMids(c *bm.Context) {
  23. v := new(struct {
  24. Op int32 `form:"operation" validate:"required"`
  25. Mids []int64 `form:"mids,split" validate:"required"`
  26. Msg string `form:"message" validate:"required"`
  27. ContentType int32 `form:"content_type"`
  28. })
  29. if err := c.Bind(v); err != nil {
  30. return
  31. }
  32. if len(v.Msg) > maxMsgSize {
  33. c.JSON(nil, ecode.FileTooLarge)
  34. return
  35. }
  36. c.JSON(nil, srv.PushMids(c, v.Op, v.Mids, v.Msg, v.ContentType))
  37. }
  38. func pushRoom(c *bm.Context) {
  39. v := new(struct {
  40. Op int32 `form:"operation" validate:"required"`
  41. Room string `form:"room" validate:"required"`
  42. Msg string `form:"message" validate:"required"`
  43. ContentType int32 `form:"content_type"`
  44. })
  45. if err := c.Bind(v); err != nil {
  46. return
  47. }
  48. if len(v.Msg) > maxMsgSize {
  49. c.JSON(nil, ecode.FileTooLarge)
  50. return
  51. }
  52. c.JSON(nil, srv.PushRoom(c, v.Op, v.Room, v.Msg, v.ContentType))
  53. }
  54. func pushAll(c *bm.Context) {
  55. v := new(struct {
  56. Op int32 `form:"operation" validate:"required"`
  57. Speed int32 `form:"speed" validate:"min=0"`
  58. Msg string `form:"message" validate:"required"`
  59. Platform string `form:"platform"`
  60. ContentType int32 `form:"content_type"`
  61. })
  62. if err := c.Bind(v); err != nil {
  63. return
  64. }
  65. if len(v.Msg) > maxMsgSize {
  66. c.JSON(nil, ecode.FileTooLarge)
  67. return
  68. }
  69. c.JSON(nil, srv.PushAll(c, v.Op, v.Speed, v.Msg, v.Platform, v.ContentType))
  70. }