(filePath string)
| 23 | } |
| 24 | |
| 25 | func (sf *SensitiveFilter) LoadFromFile(filePath string) error { |
| 26 | file, err := os.Open(filePath) |
| 27 | if err != nil { |
| 28 | return fmt.Errorf("无法打开文件: %w", err) |
| 29 | } |
| 30 | defer file.Close() |
| 31 | |
| 32 | reader := bufio.NewReader(file) |
| 33 | for { |
| 34 | line, err := reader.ReadString('\n') |
| 35 | if err != nil { |
| 36 | if err == io.EOF { |
| 37 | break |
| 38 | } |
| 39 | return fmt.Errorf("读取文件出错: %w", err) |
| 40 | } |
| 41 | word := strings.TrimSpace(line) |
| 42 | if word != "" { |
| 43 | sf.AddKeyword(word) |
| 44 | } |
| 45 | } |
| 46 | return nil |
| 47 | } |
| 48 | |
| 49 | func (sf *SensitiveFilter) AddKeyword(keyword string) { |
| 50 | node := sf.root |
no test coverage detected