summaryrefslogtreecommitdiff
path: root/plugin
diff options
context:
space:
mode:
authorLoyalsoldier <[email protected]>2024-08-06 05:15:45 +0800
committerLoyalsoldier <[email protected]>2024-08-06 05:15:45 +0800
commit38d59d447932375cc11f91b09ffff71498eaf32e (patch)
treef634840deb427da9f7a230513b3b4172c2b86512 /plugin
parentb5b24293ef86fd00d2673b1133b853a511ef9211 (diff)
Feat: support extended text format with prefix & suffix in line as output
Output plaintext CIDR with prefix and suffix in one line by using `text` format as output, specified by args `addPrefixInLine` and `addSuffixInLine`
Diffstat (limited to 'plugin')
-rw-r--r--plugin/plaintext/common_out.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/plugin/plaintext/common_out.go b/plugin/plaintext/common_out.go
index ff4ab63b..cb38345d 100644
--- a/plugin/plaintext/common_out.go
+++ b/plugin/plaintext/common_out.go
@@ -25,6 +25,9 @@ type textOut struct {
OutputDir string
Want []string
OnlyIPType lib.IPType
+
+ AddPrefixInLine string
+ AddSuffixInLine string
}
func newTextOut(iType string, action lib.Action, data json.RawMessage) (lib.OutputConverter, error) {
@@ -32,6 +35,9 @@ func newTextOut(iType string, action lib.Action, data json.RawMessage) (lib.Outp
OutputDir string `json:"outputDir"`
Want []string `json:"wantedList"`
OnlyIPType lib.IPType `json:"onlyIPType"`
+
+ AddPrefixInLine string `json:"addPrefixInLine"`
+ AddSuffixInLine string `json:"addSuffixInLine"`
}
if len(data) > 0 {
@@ -60,6 +66,9 @@ func newTextOut(iType string, action lib.Action, data json.RawMessage) (lib.Outp
OutputDir: tmp.OutputDir,
Want: tmp.Want,
OnlyIPType: tmp.OnlyIPType,
+
+ AddPrefixInLine: tmp.AddPrefixInLine,
+ AddSuffixInLine: tmp.AddSuffixInLine,
}, nil
}
@@ -101,7 +110,13 @@ func (t *textOut) marshalBytes(entry *lib.Entry) ([]byte, error) {
func (t *textOut) marshalBytesForTextOut(buf *bytes.Buffer, entryCidr []string) error {
for _, cidr := range entryCidr {
+ if t.AddPrefixInLine != "" {
+ buf.WriteString(t.AddPrefixInLine)
+ }
buf.WriteString(cidr)
+ if t.AddSuffixInLine != "" {
+ buf.WriteString(t.AddSuffixInLine)
+ }
buf.WriteString("\n")
}
return nil
@@ -149,6 +164,9 @@ func (t *textOut) marshalBytesForSurgeRuleSetOut(buf *bytes.Buffer, entryCidr []
buf.WriteString("IP-CIDR6,")
}
buf.WriteString(cidr)
+ if t.AddSuffixInLine != "" {
+ buf.WriteString(t.AddSuffixInLine)
+ }
buf.WriteString("\n")
}