Compare commits
No commits in common. "main" and "v1.0.0" have entirely different histories.
2 changed files with 1 additions and 47 deletions
|
@ -74,7 +74,7 @@ sudo install -Dm755 logdebarker /usr/local/bin/logdebarker
|
||||||
|
|
||||||
OR
|
OR
|
||||||
|
|
||||||
`go install archuser.org/logdebarker@latest`
|
`go install archuser.org/logdebarker`
|
||||||
|
|
||||||
## Final notes
|
## Final notes
|
||||||
|
|
||||||
|
|
46
main.go
46
main.go
|
@ -49,11 +49,6 @@ func loadBlockedWords(path string) {
|
||||||
redaction = strings.TrimSpace(strings.TrimPrefix(line, "redaction:"))
|
redaction = strings.TrimSpace(strings.TrimPrefix(line, "redaction:"))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(line, "import:") {
|
|
||||||
dirPath := strings.TrimSpace(strings.TrimPrefix(line, "import:"))
|
|
||||||
expandAndImportDir(dirPath)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
blockedWords = append(blockedWords, regexp.MustCompile(regexp.QuoteMeta(line)))
|
blockedWords = append(blockedWords, regexp.MustCompile(regexp.QuoteMeta(line)))
|
||||||
}
|
}
|
||||||
if err := scanner.Err(); err != nil {
|
if err := scanner.Err(); err != nil {
|
||||||
|
@ -61,39 +56,6 @@ func loadBlockedWords(path string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func expandAndImportDir(dir string) {
|
|
||||||
expandedPath := os.ExpandEnv(strings.ReplaceAll(dir, "~", getHomeDir()))
|
|
||||||
err := filepath.Walk(expandedPath, func(path string, info os.FileInfo, err error) error {
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if !info.IsDir() {
|
|
||||||
importWordsFromFile(path)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("Warning: Failed to walk directory %s: %v", dir, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func importWordsFromFile(path string) {
|
|
||||||
file, err := os.Open(path)
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("Warning: Cannot open import file %s: %v", path, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer file.Close()
|
|
||||||
|
|
||||||
scanner := bufio.NewScanner(file)
|
|
||||||
for scanner.Scan() {
|
|
||||||
line := strings.TrimSpace(scanner.Text())
|
|
||||||
if line != "" && !strings.HasPrefix(line, "#") {
|
|
||||||
blockedWords = append(blockedWords, regexp.MustCompile(regexp.QuoteMeta(line)))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func censorLine(line string) string {
|
func censorLine(line string) string {
|
||||||
for _, re := range blockedWords {
|
for _, re := range blockedWords {
|
||||||
line = re.ReplaceAllString(line, redaction)
|
line = re.ReplaceAllString(line, redaction)
|
||||||
|
@ -168,11 +130,3 @@ func isInputFromTerminal() bool {
|
||||||
return (fileInfo.Mode() & os.ModeCharDevice) != 0
|
return (fileInfo.Mode() & os.ModeCharDevice) != 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func getHomeDir() string {
|
|
||||||
usr, err := user.Current()
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Unable to determine home directory: %v", err)
|
|
||||||
}
|
|
||||||
return usr.HomeDir
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue