summaryrefslogtreecommitdiff
path: root/plugin/plaintext
diff options
context:
space:
mode:
authorLoyalsoldier <[email protected]>2024-08-13 08:36:12 +0800
committerLoyalsoldier <[email protected]>2024-08-13 10:24:46 +0800
commit50ed45ced0f436f1a2817390df46f85a953af675 (patch)
tree8e606bec1a72ec7a249e7fd3185c5afb8e3772dc /plugin/plaintext
parent56cd72d97f058fc6e931995039d69cd4b35084ec (diff)
Refine: wantedList in various formats
Diffstat (limited to 'plugin/plaintext')
-rw-r--r--plugin/plaintext/common_in.go1
-rw-r--r--plugin/plaintext/common_out.go11
-rw-r--r--plugin/plaintext/text_in.go19
-rw-r--r--plugin/plaintext/text_out.go14
4 files changed, 33 insertions, 12 deletions
diff --git a/plugin/plaintext/common_in.go b/plugin/plaintext/common_in.go
index 4c8d48c6..bf678e37 100644
--- a/plugin/plaintext/common_in.go
+++ b/plugin/plaintext/common_in.go
@@ -18,6 +18,7 @@ type textIn struct {
Name string
URI string
InputDir string
+ Want map[string]bool
OnlyIPType lib.IPType
JSONPath []string
diff --git a/plugin/plaintext/common_out.go b/plugin/plaintext/common_out.go
index ddc8d662..b8f1bb55 100644
--- a/plugin/plaintext/common_out.go
+++ b/plugin/plaintext/common_out.go
@@ -7,6 +7,7 @@ import (
"net"
"os"
"path/filepath"
+ "strings"
"github.com/Loyalsoldier/geoip/lib"
)
@@ -65,13 +66,21 @@ func newTextOut(iType string, action lib.Action, data json.RawMessage) (lib.Outp
tmp.OutputExt = ".txt"
}
+ // Filter want list
+ wantList := make([]string, 0, len(tmp.Want))
+ for _, want := range tmp.Want {
+ if want = strings.ToUpper(strings.TrimSpace(want)); want != "" {
+ wantList = append(wantList, want)
+ }
+ }
+
return &textOut{
Type: iType,
Action: action,
Description: descTextOut,
OutputDir: tmp.OutputDir,
OutputExt: tmp.OutputExt,
- Want: tmp.Want,
+ Want: wantList,
OnlyIPType: tmp.OnlyIPType,
AddPrefixInLine: tmp.AddPrefixInLine,
diff --git a/plugin/plaintext/text_in.go b/plugin/plaintext/text_in.go
index 4f2c2c71..037271c1 100644
--- a/plugin/plaintext/text_in.go
+++ b/plugin/plaintext/text_in.go
@@ -31,6 +31,7 @@ func newTextIn(iType string, action lib.Action, data json.RawMessage) (lib.Input
Name string `json:"name"`
URI string `json:"uri"`
InputDir string `json:"inputDir"`
+ Want []string `json:"wantedList"`
OnlyIPType lib.IPType `json:"onlyIPType"`
JSONPath []string `json:"jsonPath"`
@@ -60,6 +61,14 @@ func newTextIn(iType string, action lib.Action, data json.RawMessage) (lib.Input
return nil, fmt.Errorf("type %s | action %s missing jsonPath", typeJSONIn, action)
}
+ // Filter want list
+ wantList := make(map[string]bool)
+ for _, want := range tmp.Want {
+ if want = strings.ToUpper(strings.TrimSpace(want)); want != "" {
+ wantList[want] = true
+ }
+ }
+
return &textIn{
Type: iType,
Action: action,
@@ -67,6 +76,7 @@ func newTextIn(iType string, action lib.Action, data json.RawMessage) (lib.Input
Name: tmp.Name,
URI: tmp.URI,
InputDir: tmp.InputDir,
+ Want: wantList,
OnlyIPType: tmp.OnlyIPType,
JSONPath: tmp.JSONPath,
@@ -179,6 +189,10 @@ func (t *textIn) walkLocalFile(path, name string, entries map[string]*lib.Entry)
}
entryName = strings.ToUpper(entryName)
+
+ if len(t.Want) > 0 && !t.Want[entryName] {
+ return nil
+ }
if _, found := entries[entryName]; found {
return fmt.Errorf("found duplicated list %s", entryName)
}
@@ -210,6 +224,11 @@ func (t *textIn) walkRemoteFile(url, name string, entries map[string]*lib.Entry)
}
name = strings.ToUpper(name)
+
+ if len(t.Want) > 0 && !t.Want[name] {
+ return nil
+ }
+
entry := lib.NewEntry(name)
if err := t.scanFile(resp.Body, entry); err != nil {
return err
diff --git a/plugin/plaintext/text_out.go b/plugin/plaintext/text_out.go
index bc8f904e..dce92ce8 100644
--- a/plugin/plaintext/text_out.go
+++ b/plugin/plaintext/text_out.go
@@ -36,15 +36,7 @@ func (t *textOut) GetDescription() string {
}
func (t *textOut) Output(container lib.Container) error {
- // Filter want list
- wantList := make([]string, 0, 50)
- for _, want := range t.Want {
- if want = strings.ToUpper(strings.TrimSpace(want)); want != "" {
- wantList = append(wantList, want)
- }
- }
-
- switch len(wantList) {
+ switch len(t.Want) {
case 0:
list := make([]string, 0, 300)
for entry := range container.Loop() {
@@ -72,9 +64,9 @@ func (t *textOut) Output(container lib.Container) error {
default:
// Sort the list
- slices.Sort(wantList)
+ slices.Sort(t.Want)
- for _, name := range wantList {
+ for _, name := range t.Want {
entry, found := container.GetEntry(name)
if !found {
log.Printf("❌ entry %s not found", name)