http.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. package block
  2. // ParamValidator .
  3. type ParamValidator interface {
  4. Validate() bool
  5. }
  6. // ParamInfo .
  7. type ParamInfo struct {
  8. MID int64 `form:"mid"`
  9. }
  10. // Validate .
  11. func (p *ParamInfo) Validate() bool {
  12. return p.MID > 0
  13. }
  14. // ParamBatchInfo .
  15. type ParamBatchInfo struct {
  16. MIDs []int64 `form:"mids,split"`
  17. }
  18. // Validate .
  19. func (p *ParamBatchInfo) Validate() bool {
  20. if len(p.MIDs) == 0 || len(p.MIDs) > 20 {
  21. return false
  22. }
  23. return true
  24. }
  25. // ParamBatchDetail .
  26. type ParamBatchDetail struct {
  27. MIDs []int64 `form:"mids,split"`
  28. }
  29. // Validate .
  30. func (p *ParamBatchDetail) Validate() bool {
  31. if len(p.MIDs) == 0 || len(p.MIDs) > 20 {
  32. return false
  33. }
  34. return true
  35. }
  36. // ParamBlock .
  37. type ParamBlock struct {
  38. MID int64 `form:"mid"`
  39. Source BlockSource `form:"source"`
  40. Area BlockArea `form:"area"`
  41. Action BlockAction `form:"action"`
  42. Duration int64 `form:"duration"` // unix time
  43. StartTime int64 `form:"start_time"`
  44. OperatorID int `form:"op_id"`
  45. Operator string `form:"operator"`
  46. Reason string `form:"reason"`
  47. Comment string `form:"comment"`
  48. Notify bool `form:"notify"`
  49. }
  50. // Validate .
  51. func (p *ParamBlock) Validate() bool {
  52. if p.MID <= 0 {
  53. return false
  54. }
  55. if !p.Source.Contain() {
  56. return false
  57. }
  58. if p.Action != BlockActionLimit && p.Action != BlockActionForever {
  59. return false
  60. }
  61. if p.StartTime <= 0 {
  62. return false
  63. }
  64. if p.Action == BlockActionLimit {
  65. if p.Duration <= 0 {
  66. return false
  67. }
  68. }
  69. return true
  70. }
  71. // ParamBatchBlock .
  72. type ParamBatchBlock struct {
  73. MIDs []int64 `form:"mids,split"`
  74. Source BlockSource `form:"source"`
  75. Area BlockArea `form:"area"`
  76. Action BlockAction `form:"action"`
  77. Duration int64 `form:"duration"` // unix time
  78. StartTime int64 `form:"start_time"`
  79. OperatorID int `form:"op_id"`
  80. Operator string `form:"operator"`
  81. Reason string `form:"reason"`
  82. Comment string `form:"comment"`
  83. Notify bool `form:"notify"`
  84. }
  85. // Validate .
  86. func (p *ParamBatchBlock) Validate() bool {
  87. if len(p.MIDs) == 0 || len(p.MIDs) > 20 {
  88. return false
  89. }
  90. if !p.Source.Contain() {
  91. return false
  92. }
  93. if p.Action != BlockActionLimit && p.Action != BlockActionForever {
  94. return false
  95. }
  96. if p.StartTime <= 0 {
  97. return false
  98. }
  99. if p.Action == BlockActionLimit {
  100. if p.Duration <= 0 {
  101. return false
  102. }
  103. }
  104. return true
  105. }
  106. // ParamRemove .
  107. type ParamRemove struct {
  108. MID int64 `form:"mid"`
  109. Source BlockSource `form:"source"`
  110. OperatorID int `form:"op_id"`
  111. Operator string `form:"operator"`
  112. Reason string `form:"reason"`
  113. Comment string `form:"comment"`
  114. Notify bool `form:"notify"`
  115. }
  116. // Validate .
  117. func (p *ParamRemove) Validate() bool {
  118. if p.MID <= 0 {
  119. return false
  120. }
  121. if !p.Source.Contain() {
  122. return false
  123. }
  124. return true
  125. }
  126. // ParamBatchRemove .
  127. type ParamBatchRemove struct {
  128. MIDs []int64 `form:"mids,split"`
  129. Source BlockSource `form:"source"`
  130. OperatorID int `form:"op_id"`
  131. Operator string `form:"operator"`
  132. Reason string `form:"reason"`
  133. Comment string `form:"comment"`
  134. Notify bool `form:"notify"`
  135. }
  136. // Validate .
  137. func (p *ParamBatchRemove) Validate() bool {
  138. if len(p.MIDs) == 0 || len(p.MIDs) > 20 {
  139. return false
  140. }
  141. if !p.Source.Contain() {
  142. return false
  143. }
  144. return true
  145. }