With golang wrote sensitive word filtering tool, mainly used to detect the existence of sensitive words in the user nickname, while providing the function of eliminating the transfer of characters.
You can start by putting the sensitive word inventory in a MAP, sensitive words can be found here:/fwwdn/sensitive-stop-words
Pass in map and nickname, and the program checks each substring of the nickname to determine if it is in the map sensitive lexicon. Complexity O(len(name)^2)
package util import ( "/pkg/errors" "strings" ) type filter struct { data string maxLimitLen int } func NewKeywordFilter(str string, maxLimitLen int) (*filter, error) { if len(str) > maxLimitLen { return nil, ("Length: %d, cannot exceed: %d", len(str), maxLimitLen) } return &filter{ data: str, maxLimitLen: maxLimitLen, }, nil } func (f *filter) GetData() string { return } func (f *filter) FilterKeywords(keywords map[string]bool) (err error) { if keywords == nil { return } for i := 0; i < len(); i++ { for j := i + 1; j <= len(); j++ { subStr := [i:j] if _, found := keywords[subStr]; found { err = ("Nickname violation, suggest change.") } } } return } func (f *filter) TrimAllCharset(ch []string) (err error) { if ch == nil { return } for _, c := range ch { = (, c, "", -1) } if len() == 0 { err = ("The length of the data is 0 after excluding the relevant transfer characters.") return } return }
This article on the implementation of golang sensitive word filtering is introduced to this article, more related golang sensitive word filtering content please search for my previous articles or continue to browse the following related articles I hope you will support me in the future more!