互动
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.0 KiB

5 years ago
  1. package models
  2. import (
  3. "github.com/ouxuanserver/osmanthuswine/src/core"
  4. "strings"
  5. "time"
  6. )
  7. type Sensitive struct {
  8. Id int64 `json:"id"`
  9. Keyword string `json:"keyword" description:"关键字"`
  10. Host string `json:"host" description:"二级域名"`
  11. Category string `json:"category" description:"类别"`
  12. IsDelete bool `json:"is_delete" xorm:"default(0)" description:"是否已删除"`
  13. CreateAt time.Time `json:"create_at" xorm:"created"`
  14. UpdateAt time.Time `json:"update_at" xorm:"updated"`
  15. }
  16. var (
  17. cacheSensitive = make([]*Sensitive, 0)
  18. currentSensitiveTime = time.Time{}
  19. )
  20. func GetSensitive() []*Sensitive {
  21. if len(cacheSensitive) == 0 || time.Now().Sub(currentSensitiveTime).Hours() > 24 {
  22. core.GetXormAuto().Where("is_delete=0").Find(&cacheSensitive)
  23. currentSensitiveTime = time.Now()
  24. }
  25. return cacheSensitive
  26. }
  27. //匹配是否包含敏感字眼
  28. func IsSensitive(str string) bool {
  29. for _, v := range GetSensitive() {
  30. if strings.Contains(str, v.Keyword) {
  31. return true
  32. }
  33. }
  34. return false
  35. }