互动
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.

26 lines
383 B

  1. package filter
  2. import (
  3. "github.com/importcjj/sensitive"
  4. "os"
  5. "path/filepath"
  6. )
  7. var filter *sensitive.Filter
  8. func init() {
  9. initFilter()
  10. }
  11. func initFilter() {
  12. wd, _ := os.Getwd()
  13. filter = sensitive.New()
  14. filter.LoadWordDict(filepath.Join(wd, "keywords"))
  15. }
  16. func Replace(content string) string {
  17. if filter == nil {
  18. initFilter()
  19. }
  20. return filter.Replace(content, '*')
  21. }