From 41c6f52742fca98e1be20d06ebf238659cbb0d6e Mon Sep 17 00:00:00 2001 From: Loyalsoldier <10487845+Loyalsoldier@users.noreply.github.com> Date: Thu, 15 Aug 2024 12:39:49 +0800 Subject: [PATCH] Feat: support to add prefix & suffix to text output format --- plugin/plaintext/text_out.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/plugin/plaintext/text_out.go b/plugin/plaintext/text_out.go index 91f959085..be6775aa2 100644 --- a/plugin/plaintext/text_out.go +++ b/plugin/plaintext/text_out.go @@ -35,6 +35,9 @@ func newTextOut(action lib.Action, data json.RawMessage) (lib.OutputConverter, e 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 { @@ -62,6 +65,9 @@ func newTextOut(action lib.Action, data json.RawMessage) (lib.OutputConverter, e OutputDir: tmp.OutputDir, Want: wantList, OnlyIPType: tmp.OnlyIPType, + + AddPrefixInLine: tmp.AddPrefixInLine, + AddSuffixInLine: tmp.AddSuffixInLine, }, nil } @@ -72,6 +78,9 @@ type textOut struct { OutputDir string Want []string OnlyIPType lib.IPType + + AddPrefixInLine string + AddSuffixInLine string } func (t *textOut) GetType() string { @@ -164,7 +173,13 @@ func (t *textOut) marshalText(entry *lib.Entry) ([]string, error) { func (t *textOut) writeFile(filename string, cidrList []string) error { var buf bytes.Buffer for _, cidr := range cidrList { + if t.AddPrefixInLine != "" { + buf.WriteString(t.AddPrefixInLine) + } buf.WriteString(cidr) + if t.AddSuffixInLine != "" { + buf.WriteString(t.AddSuffixInLine) + } buf.WriteString("\n") } cidrBytes := buf.Bytes()