upper.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package ugc
  2. import "strings"
  3. // Upper reprensents the uppers
  4. type Upper struct {
  5. MID int64
  6. Toinit int
  7. Submit int // 1=need report
  8. OriName string // original name
  9. CMSName string // cms intervened name
  10. OriFace string // original face
  11. CMSFace string // cms intervened face
  12. Valid int // auth info: 1=online,0=hidden
  13. Deleted int
  14. }
  15. // EasyUp is the simple version of upper
  16. type EasyUp struct {
  17. MID int64
  18. Name string
  19. Face string
  20. }
  21. // ToUpper transform an EasyUp to Upper
  22. func (u *EasyUp) ToUpper(ori *Upper) *Upper {
  23. if ori == nil { // if no original data is given
  24. ori = &Upper{
  25. Valid: 1,
  26. }
  27. }
  28. return &Upper{
  29. MID: u.MID,
  30. OriFace: u.Face,
  31. CMSFace: u.Face,
  32. OriName: u.Name,
  33. CMSName: u.Name,
  34. Toinit: ori.Toinit,
  35. Submit: ori.Submit,
  36. Valid: ori.Valid,
  37. Deleted: ori.Deleted,
  38. }
  39. }
  40. // IsSame returns whether the upper is the same
  41. func (u *Upper) IsSame(name, face string) (f bool, n bool) {
  42. n = u.OriName == name
  43. if strings.Contains(u.OriFace, "bfs") &&
  44. strings.Contains(face, "bfs") {
  45. f = bfsFName(u.OriFace) == bfsFName(face)
  46. } else {
  47. f = u.OriFace == face
  48. }
  49. return
  50. }
  51. // bfsFName picks the file name from bfs url
  52. func bfsFName(bfsurl string) (fileName string) {
  53. var index = strings.LastIndex(bfsurl, "/")
  54. if index >= 0 && index+1 < len(bfsurl) {
  55. fileName = bfsurl[index+1:]
  56. }
  57. return
  58. }
  59. // ReqSetUp is the structure of request to function in Dao, set upper value
  60. type ReqSetUp struct {
  61. Value string
  62. MID int64
  63. UpType int
  64. }