http.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. package model
  2. // ParamValidator .
  3. type ParamValidator interface {
  4. Validate() bool
  5. }
  6. // ParamSearch .
  7. type ParamSearch struct {
  8. MIDs []int64 `form:"mids,split"`
  9. }
  10. // Validate .
  11. func (p *ParamSearch) Validate() bool {
  12. p.MIDs = intsSet(p.MIDs)
  13. if len(p.MIDs) == 0 || len(p.MIDs) > 200 {
  14. return false
  15. }
  16. return true
  17. }
  18. // ParamHistory .
  19. type ParamHistory struct {
  20. MID int64 `form:"mid"`
  21. PS int `form:"ps"`
  22. PN int `form:"pn"`
  23. }
  24. // Validate .
  25. func (p *ParamHistory) Validate() bool {
  26. if p.MID <= 0 {
  27. return false
  28. }
  29. if p.PS <= 0 || p.PS > 100 {
  30. return false
  31. }
  32. if p.PN <= 0 {
  33. return false
  34. }
  35. return true
  36. }
  37. // ParamBatchBlock .
  38. type ParamBatchBlock struct {
  39. MIDs []int64 `form:"mids,split"`
  40. AdminID int64 `form:"admin_id"`
  41. AdminName string `form:"admin_name"`
  42. Source int `form:"source"` //1 系统封禁 2 小黑屋封禁
  43. Area BlockArea `form:"area"`
  44. Reason string `form:"reason"`
  45. Comment string `form:"comment"`
  46. Action BlockAction `form:"action"`
  47. Duration int64 `form:"duration"` // 单位:天
  48. Notify bool `form:"notify"`
  49. }
  50. // Validate .
  51. func (p *ParamBatchBlock) Validate() bool {
  52. p.MIDs = intsSet(p.MIDs)
  53. if len(p.MIDs) == 0 || len(p.MIDs) > 200 {
  54. return false
  55. }
  56. if p.AdminID <= 0 {
  57. return false
  58. }
  59. if p.AdminName == "" {
  60. return false
  61. }
  62. if p.Source != 1 && p.Source != 2 {
  63. return false
  64. }
  65. if !p.Area.Contain() {
  66. return false
  67. }
  68. if p.Comment == "" {
  69. return false
  70. }
  71. if p.Action != BlockActionForever && p.Action != BlockActionLimit {
  72. return false
  73. }
  74. if p.Action == BlockActionLimit {
  75. if p.Duration <= 0 {
  76. return false
  77. }
  78. }
  79. return true
  80. }
  81. // ParamBatchRemove .
  82. type ParamBatchRemove struct {
  83. MIDs []int64 `form:"mids,split"`
  84. AdminID int64 `form:"admin_id"`
  85. AdminName string `form:"admin_name"`
  86. Comment string `form:"comment"`
  87. Notify bool `form:"notify"`
  88. }
  89. // Validate .
  90. func (p *ParamBatchRemove) Validate() bool {
  91. p.MIDs = intsSet(p.MIDs)
  92. if len(p.MIDs) == 0 || len(p.MIDs) > 200 {
  93. return false
  94. }
  95. if p.AdminID <= 0 {
  96. return false
  97. }
  98. if p.AdminName == "" {
  99. return false
  100. }
  101. if p.Comment == "" {
  102. return false
  103. }
  104. return true
  105. }
  106. func intsSet(ints []int64) (intSet []int64) {
  107. if len(ints) == 0 {
  108. return
  109. }
  110. OUTER:
  111. for i := range ints {
  112. for ni := range intSet {
  113. if ints[i] == intSet[ni] {
  114. continue OUTER
  115. }
  116. }
  117. intSet = append(intSet, ints[i])
  118. }
  119. return
  120. }