up.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package model
  2. const (
  3. // IsUp is up
  4. IsUp = 1
  5. // NotUp not up
  6. NotUp = 0
  7. )
  8. //Up for db.
  9. type Up struct {
  10. ID int64 `json:"id"`
  11. MID int64 `json:"mid"`
  12. Attribute int `json:"attribute"`
  13. }
  14. //Info for auth by all platform
  15. type Info struct {
  16. Archive int `json:"archive"`
  17. ArchiveFake int `json:"archive_fake"`
  18. }
  19. // IdentifyAll for all type of uper identify.
  20. type IdentifyAll struct {
  21. Archive int `json:"archive"`
  22. Article int `json:"article"`
  23. Pic int `json:"pic"`
  24. Blink int `json:"blink"`
  25. }
  26. // AttrSet set attribute.
  27. func (u *Up) AttrSet(v int, bit uint8) {
  28. u.Attribute = u.Attribute&(^(1 << bit)) | (v << bit)
  29. }
  30. // AttrVal get attribute.
  31. func (u *Up) AttrVal(bit uint8) int {
  32. return (u.Attribute >> bit) & int(1)
  33. }
  34. // Const State
  35. const (
  36. // AttrNo attribute yes and no
  37. AttrNo = int(0)
  38. AttrYes = int(1)
  39. // AttrArchiveUp attribute bit
  40. AttrArchiveUp = uint8(0)
  41. AttrArchiveNewUp = uint8(1)
  42. AttrLiveUp = uint8(2)
  43. AttrLiveWhiteUp = uint8(3)
  44. )
  45. var (
  46. _attr = map[int]int{
  47. AttrNo: AttrNo,
  48. AttrYes: AttrYes,
  49. }
  50. _bits = map[uint8]string{
  51. AttrArchiveUp: "稿件作者-有过审稿",
  52. AttrArchiveNewUp: "稿件作者-有投过稿",
  53. AttrLiveUp: "直播作者",
  54. AttrLiveWhiteUp: "直播白名单",
  55. }
  56. )
  57. // BitDesc return bit desc.
  58. func BitDesc(bit uint8) (desc string) {
  59. return _bits[bit]
  60. }
  61. // InAttr in correct attrs.
  62. func InAttr(attr int) (ok bool) {
  63. _, ok = _attr[attr]
  64. return
  65. }
  66. // ListUpBaseArg arg
  67. type ListUpBaseArg struct {
  68. LastID int64 `form:"last_id"`
  69. Size int `form:"size"`
  70. Activity []int64 `form:"activity,split"`
  71. }
  72. // Validate ListUpBaseArg
  73. func (arg *ListUpBaseArg) Validate() bool {
  74. if arg.Size < 0 || arg.Size > 1000 || arg.LastID < 0 {
  75. return false
  76. }
  77. if len(arg.Activity) > 0 {
  78. for _, v := range arg.Activity {
  79. if v < 0 || v > 4 {
  80. return false
  81. }
  82. }
  83. }
  84. return true
  85. }