敏感词过滤

This commit is contained in:
Rosy-zhudan
2019-08-16 14:26:22 +08:00
parent 634ac5ebe6
commit 4636ea7fd5
8 changed files with 90 additions and 4 deletions

View File

@@ -0,0 +1,32 @@
package dao
import (
"strings"
"git.rosy.net.cn/jx-callback/business/model"
)
func GetSensitiveWordList() (wordList []*model.SensitiveWords, err error) {
sql := `SELECT * FROM sensitive_words`
err = GetRows(nil, &wordList, sql)
return wordList, err
}
func InsertSensitiveWord(word string) error {
return CreateEntity(nil, &model.SensitiveWords{Words: word})
}
func CheckHasSensitiveWord(str string) (bool, string) {
wordList, err := GetSensitiveWordList()
if err == nil {
for _, value := range wordList {
keyWord := value.Words
checkHas := strings.Contains(str, keyWord)
if checkHas {
return true, keyWord
}
}
}
return false, ""
}

View File

@@ -0,0 +1,6 @@
package model
type SensitiveWords struct {
ID int `orm:"column(id)" json:"id"`
Words string `orm:"size(30);column(words);unique" json:"words"`
}