Categorygithub.com/sgoware/go-sensitive
modulepackage
1.0.4
Repository: https://github.com/sgoware/go-sensitive.git
Documentation: pkg.go.dev

# README

🚫 go-sensitive

buildgo-version

English | δΈ­ζ–‡

Filter sensitive words, support multiple data sources, filter algorithms and functions

🌟 Feature

  • support multiple functions
    • Filter() return filtered text
    • Replace() return text which sensitive words that is been replaced
    • IsSensitive() Check whether the text has sensitive word
    • FindOne() return first sensitive word that has been found in the text
    • FindAll() return all sensitive word that has been found in the text
    • FindAllCount() return all sensitiveREADME-zh_cn.md word with its count that has been found in the text
  • support multiple data sources with dynamic modification
    • support memory storage
    • support mysql storage
    • support mongo storage
    • support multiple ways of add dict
    • support dynamic add/del sensitive word while running
  • support multiple filter algorithms
    • DFA use trie tree to filter sensitive words
    • Aho–Corasick algorithm

βš™ Usage

package main

import (
	"fmt"
	"github.com/sgoware/go-sensitive"
)

func main() {
    filterManager := sensitive.NewFilter(
        sensitive.StoreOption{
            Type: sensitive.StoreMemory
        },
        sensitive.FilterOption{
            Type: sensitive.FilterDfa
        }
    )
    
    // load dict
    
    err:=filterManager.GetStore().LoadDictPath("path-to-dict")
    if err != nil {
        fmt.Println(err)
        return
	}
    
    // dynamic add sensitive words
    
    err=filterManager.GetStore().AddWord("θΏ™ζ˜―ζ•ζ„Ÿθ―1", "θΏ™ζ˜―ζ•ζ„Ÿθ―2", "θΏ™ζ˜―ζ•ζ„Ÿθ―3")
    if err != nil {
        fmt.Println(err)
        return
	}
    
    fmt.Println(filterManager.GetFilter().IsSensitive("θΏ™ζ˜―ζ•ζ„Ÿθ―1,θΏ™ζ˜―ζ•ζ„Ÿθ―2,θΏ™ζ˜―ζ•ζ„Ÿθ―3,θΏ™ζ˜―ζ•ζ„Ÿθ―1,θΏ™ι‡Œζ²‘ζœ‰ζ•ζ„Ÿθ―"))
    
    fmt.Println(filterManager.GetFilter().Filter("θΏ™ζ˜―ζ•ζ„Ÿθ―1,θΏ™ζ˜―ζ•ζ„Ÿθ―2,θΏ™ζ˜―ζ•ζ„Ÿθ―3,θΏ™ζ˜―ζ•ζ„Ÿθ―1,θΏ™ι‡Œζ²‘ζœ‰ζ•ζ„Ÿθ―"))
    
    fmt.Println(filterManager.GetFilter().Replace("θΏ™ζ˜―ζ•ζ„Ÿθ―1,θΏ™ζ˜―ζ•ζ„Ÿθ―2,θΏ™ζ˜―ζ•ζ„Ÿθ―3,θΏ™ζ˜―ζ•ζ„Ÿθ―1,θΏ™ι‡Œζ²‘ζœ‰ζ•ζ„Ÿθ―", '*'))
    
    fmt.Println(filterManager.GetFilter().FindOne("θΏ™ζ˜―ζ•ζ„Ÿθ―1,θΏ™ζ˜―ζ•ζ„Ÿθ―2,θΏ™ζ˜―ζ•ζ„Ÿθ―3,θΏ™ζ˜―ζ•ζ„Ÿθ―1,θΏ™ι‡Œζ²‘ζœ‰ζ•ζ„Ÿθ―"))

    fmt.Println(filterManager.GetFilter().FindAll("θΏ™ζ˜―ζ•ζ„Ÿθ―1,θΏ™ζ˜―ζ•ζ„Ÿθ―2,θΏ™ζ˜―ζ•ζ„Ÿθ―3,θΏ™ζ˜―ζ•ζ„Ÿθ―1,θΏ™ι‡Œζ²‘ζœ‰ζ•ζ„Ÿθ―"))

    fmt.Println(filterManager.GetFilter().FindAllCount("θΏ™ζ˜―ζ•ζ„Ÿθ―1,θΏ™ζ˜―ζ•ζ„Ÿθ―2,θΏ™ζ˜―ζ•ζ„Ÿθ―3,θΏ™ζ˜―ζ•ζ„Ÿθ―1,θΏ™ι‡Œζ²‘ζœ‰ζ•ζ„Ÿθ―"))
}

βœ” Get

$ go get -u github.com/sgoware/go-sensitive

πŸ“‚ Import

import "github.com/sgoware/go-sensitive"

πŸ“Œ TODO

  • add redis data source support
  • add bloom algorithm

# Packages

No description provided by the author
No description provided by the author

# Functions

No description provided by the author

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

No description provided by the author
No description provided by the author
No description provided by the author