-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
顾志明
committed
Sep 26, 2019
1 parent
69aef65
commit c143ad6
Showing
8 changed files
with
106 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
学历证书 | ||
毕业证 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ import ( | |
) | ||
|
||
const ( | ||
Version = "2.0.2" | ||
Version = "2.0.3" | ||
) | ||
|
||
var ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package utils | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"io" | ||
"strings" | ||
|
||
filter "github.com/antlinker/go-dirtyfilter" | ||
"github.com/antlinker/go-dirtyfilter/store" | ||
|
||
"github.com/jimmykuu/gopher/conf" | ||
) | ||
|
||
// NewDirtyManager 新建敏感词管理器 | ||
func NewDirtyManager(reader io.Reader) *filter.DirtyManager { | ||
buf := bufio.NewReader(reader) | ||
var words = []string{} | ||
for { | ||
line, err := buf.ReadString('\n') | ||
line = strings.TrimSpace(line) | ||
|
||
if line != "" { | ||
words = append(words, line) | ||
} | ||
|
||
if err != nil { | ||
if err == io.EOF { | ||
fmt.Println("File read ok!") | ||
break | ||
} | ||
} | ||
} | ||
|
||
memStore, err := store.NewMemoryStore(store.MemoryConfig{ | ||
DataSource: words, | ||
}) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
return filter.NewDirtyManager(memStore) | ||
} | ||
|
||
// HasSensitiveWords 是否敏感词 | ||
func HasSensitiveWords(text string) bool { | ||
result, err := conf.DirtyManager.Filter().Filter(text, '*', '@') | ||
if err != nil { | ||
fmt.Println(err) | ||
|
||
return true | ||
} | ||
|
||
fmt.Println(result) | ||
|
||
return len(result) > 0 | ||
} |