diff options
| author | Loyalsoldier <[email protected]> | 2024-08-06 04:48:42 +0800 |
|---|---|---|
| committer | Loyalsoldier <[email protected]> | 2024-08-06 04:48:42 +0800 |
| commit | b5b24293ef86fd00d2673b1133b853a511ef9211 (patch) | |
| tree | 5c9019c9e6f840a5d251f3afd53aa44efedbf14f /plugin | |
| parent | ee3687e191acbde3aabc13cf4f5dca93a3d80af5 (diff) | |
Feat: support extended text format with prefix & suffix in line as input
IP and CIDR with prefix and suffix in one line now can be processed by using `text` format as input, specified by args `removePrefixesInLine` and `removeSuffixesInLine`.
Diffstat (limited to 'plugin')
| -rw-r--r-- | plugin/plaintext/common_in.go | 22 | ||||
| -rw-r--r-- | plugin/plaintext/text_in.go | 6 |
2 files changed, 24 insertions, 4 deletions
diff --git a/plugin/plaintext/common_in.go b/plugin/plaintext/common_in.go index f5be6aa6..cbc64c00 100644 --- a/plugin/plaintext/common_in.go +++ b/plugin/plaintext/common_in.go @@ -17,6 +17,9 @@ type textIn struct { URI string InputDir string OnlyIPType lib.IPType + + RemovePrefixesInLine []string + RemoveSuffixesInLine []string } func (t *textIn) scanFile(reader io.Reader, entry *lib.Entry) error { @@ -40,10 +43,8 @@ func (t *textIn) scanFile(reader io.Reader, entry *lib.Entry) error { func (t *textIn) scanFileForTextIn(reader io.Reader, entry *lib.Entry) error { scanner := bufio.NewScanner(reader) for scanner.Scan() { - line := strings.TrimSpace(scanner.Text()) - if line == "" { - continue - } + line := scanner.Text() + line, _, _ = strings.Cut(line, "#") line, _, _ = strings.Cut(line, "//") line, _, _ = strings.Cut(line, "/*") @@ -51,6 +52,19 @@ func (t *textIn) scanFileForTextIn(reader io.Reader, entry *lib.Entry) error { if line == "" { continue } + + line = strings.ToLower(line) + for _, prefix := range t.RemovePrefixesInLine { + line = strings.TrimSpace(strings.TrimPrefix(line, strings.ToLower(strings.TrimSpace(prefix)))) + } + for _, suffix := range t.RemoveSuffixesInLine { + line = strings.TrimSpace(strings.TrimSuffix(line, strings.ToLower(strings.TrimSpace(suffix)))) + } + line = strings.TrimSpace(line) + if line == "" { + continue + } + if err := entry.AddPrefix(line); err != nil { return err } diff --git a/plugin/plaintext/text_in.go b/plugin/plaintext/text_in.go index 6ebf15d9..d9aea269 100644 --- a/plugin/plaintext/text_in.go +++ b/plugin/plaintext/text_in.go @@ -32,6 +32,9 @@ func newTextIn(iType string, action lib.Action, data json.RawMessage) (lib.Input URI string `json:"uri"` InputDir string `json:"inputDir"` OnlyIPType lib.IPType `json:"onlyIPType"` + + RemovePrefixesInLine []string `json:"removePrefixesInLine"` + RemoveSuffixesInLine []string `json:"removeSuffixesInLine"` } if strings.TrimSpace(iType) == "" { @@ -60,6 +63,9 @@ func newTextIn(iType string, action lib.Action, data json.RawMessage) (lib.Input URI: tmp.URI, InputDir: tmp.InputDir, OnlyIPType: tmp.OnlyIPType, + + RemovePrefixesInLine: tmp.RemovePrefixesInLine, + RemoveSuffixesInLine: tmp.RemoveSuffixesInLine, }, nil } |
