package models import ( "github.com/ouxuanserver/osmanthuswine/src/core" "strings" "time" ) type Sensitive struct { Id int64 `json:"id"` Keyword string `json:"keyword" description:"关键字"` Host string `json:"host" description:"二级域名"` Category string `json:"category" description:"类别"` IsDelete bool `json:"is_delete" xorm:"default(0)" description:"是否已删除"` CreateAt time.Time `json:"create_at" xorm:"created"` UpdateAt time.Time `json:"update_at" xorm:"updated"` } var ( cacheSensitive = make([]*Sensitive, 0) currentSensitiveTime = time.Time{} ) func GetSensitive() []*Sensitive { if len(cacheSensitive) == 0 || time.Now().Sub(currentSensitiveTime).Hours() > 24 { core.GetXormAuto().Where("is_delete=0").Find(&cacheSensitive) currentSensitiveTime = time.Now() } return cacheSensitive } //匹配是否包含敏感字眼 func IsSensitive(str string) bool { for _, v := range GetSensitive() { if strings.Contains(str, v.Keyword) { return true } } return false }