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.
33 lines
504 B
33 lines
504 B
package filter
|
|
|
|
import (
|
|
"github.com/importcjj/sensitive"
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
var filter *sensitive.Filter
|
|
|
|
func init() {
|
|
initFilter()
|
|
}
|
|
|
|
func initFilter() {
|
|
wd, _ := os.Getwd()
|
|
filter = sensitive.New()
|
|
filter.LoadWordDict(filepath.Join(wd, "keywords"))
|
|
}
|
|
|
|
func Replace(content string) string {
|
|
if filter == nil {
|
|
initFilter()
|
|
}
|
|
return filter.Replace(content, '*')
|
|
}
|
|
|
|
func Validate(content string) (bool, string) {
|
|
if filter == nil {
|
|
initFilter()
|
|
}
|
|
return filter.Validate(content)
|
|
}
|