dm_special.go 798 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package model
  2. import (
  3. "fmt"
  4. "regexp"
  5. "strings"
  6. )
  7. var (
  8. _regFmt = `.*/bfs/([\S]+)/%s.xml`
  9. )
  10. // DmSpecialContent .
  11. type DmSpecialContent struct {
  12. ID int64 `json:"id"`
  13. Content string `json:"content"`
  14. }
  15. // DmSpecial special dm bfs location
  16. type DmSpecial struct {
  17. ID int64
  18. Type int32
  19. Oid int64
  20. Locations string
  21. }
  22. // Split .
  23. func (d *DmSpecial) Split() []string {
  24. return strings.Split(d.Locations, ",")
  25. }
  26. // Join .
  27. func (d *DmSpecial) Join(s []string) {
  28. d.Locations = strings.Join(s, ",")
  29. }
  30. // Find find url if exist
  31. func (d *DmSpecial) Find(sha1Sum string) string {
  32. locations := d.Split()
  33. reg := regexp.MustCompile(fmt.Sprintf(_regFmt, sha1Sum))
  34. for _, location := range locations {
  35. if reg.MatchString(location) {
  36. return location
  37. }
  38. }
  39. return ""
  40. }