auto.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "net/url"
  6. "strconv"
  7. "go-common/library/log"
  8. "go-common/library/xstr"
  9. )
  10. // DoAvBreach av breach by api.
  11. func (d *Dao) DoAvBreach(c context.Context, mid int64, aid int64, ctype int, reason string) (err error) {
  12. params := url.Values{}
  13. params.Set("type", strconv.Itoa(ctype))
  14. params.Set("mid", strconv.FormatInt(mid, 10))
  15. params.Set("aids", strconv.FormatInt(aid, 10))
  16. params.Set("reason", reason)
  17. var res struct {
  18. Code int `json:"code"`
  19. Message string `json:"message"`
  20. }
  21. url := d.breachURL
  22. if err = d.client.Post(c, url, "", params, &res); err != nil {
  23. log.Error("d.client.Post url(%s) error(%v)", url+"?"+params.Encode(), err)
  24. return
  25. }
  26. if res.Code != 0 {
  27. log.Error("DoAvBreach code != 0. res.Code(%d) | url(%s) error(%v)", res.Code, url+"?"+params.Encode(), res.Message)
  28. err = fmt.Errorf("DoAvBreach error(%s)", res.Message)
  29. }
  30. return
  31. }
  32. // DoUpForbid up forbid by api
  33. func (d *Dao) DoUpForbid(c context.Context, mid int64, days int, ctype int, reason string) (err error) {
  34. params := url.Values{}
  35. params.Set("type", strconv.Itoa(ctype))
  36. params.Set("mid", strconv.FormatInt(mid, 10))
  37. params.Set("days", strconv.Itoa(days))
  38. params.Set("reason", reason)
  39. var res struct {
  40. Code int `json:"code"`
  41. Message string `json:"message"`
  42. }
  43. url := d.forbidURL
  44. if err = d.client.Post(c, url, "", params, &res); err != nil {
  45. log.Error("d.client.Post url(%s) error(%v)", url+"?"+params.Encode(), err)
  46. return
  47. }
  48. if res.Code != 0 {
  49. log.Error("DoUpForbid code != 0. res.Code(%d) | url(%s) error(%v)", res.Code, url+"?"+params.Encode(), res.Message)
  50. err = fmt.Errorf("DoUpForbid error(%s)", res.Message)
  51. }
  52. return
  53. }
  54. // DoUpDismiss up dismiss by api
  55. func (d *Dao) DoUpDismiss(c context.Context, mid int64, ctype int, reason string) (err error) {
  56. params := url.Values{}
  57. params.Set("type", strconv.Itoa(ctype))
  58. params.Set("mid", strconv.FormatInt(mid, 10))
  59. params.Set("reason", reason)
  60. var res struct {
  61. Code int `json:"code"`
  62. Message string `json:"message"`
  63. }
  64. url := d.dismissURL
  65. if err = d.client.Post(c, url, "", params, &res); err != nil {
  66. log.Error("d.client.Post url(%s) error(%v)", url+"?"+params.Encode(), err)
  67. return
  68. }
  69. if res.Code != 0 {
  70. log.Error("DoUpDismiss code != 0. res.Code(%d) | url(%s) error(%v)", res.Code, url+"?"+params.Encode(), res.Message)
  71. err = fmt.Errorf("DoUpDismiss error(%s)", res.Message)
  72. }
  73. return
  74. }
  75. // DoUpPass up pass by api
  76. func (d *Dao) DoUpPass(c context.Context, mids []int64, ctype int) (err error) {
  77. params := url.Values{}
  78. params.Set("type", strconv.Itoa(ctype))
  79. params.Set("mids", xstr.JoinInts(mids))
  80. var res struct {
  81. Code int `json:"code"`
  82. Message string `json:"message"`
  83. }
  84. url := d.passURL
  85. if err = d.client.Post(c, url, "", params, &res); err != nil {
  86. log.Error("d.client.Post url(%s) error(%v)", url+"?"+params.Encode(), err)
  87. return
  88. }
  89. if res.Code != 0 {
  90. log.Error("DoUpPass code != 0. res.Code(%d) | url(%s) error(%v)", res.Code, url+"?"+params.Encode(), res.Message)
  91. err = fmt.Errorf("DoUpPass error(%s)", res.Message)
  92. }
  93. return
  94. }