summaryrefslogtreecommitdiff
path: root/plugin/special
diff options
context:
space:
mode:
authorLoyalsoldier <[email protected]>2024-10-31 10:51:58 +0800
committerLoyalsoldier <[email protected]>2024-10-31 11:21:57 +0800
commit883184cbdc5fff0763c56aae7b08b0605dc08a9b (patch)
treeb1def962ecffe4c2d4be37e77597dd4772ae3e1f /plugin/special
parent1e26c9803d42d3601c75c4db2ee3ff565b6388d8 (diff)
Feat: export input & output converters
Diffstat (limited to 'plugin/special')
-rw-r--r--plugin/special/cutter.go30
-rw-r--r--plugin/special/lookup.go28
-rw-r--r--plugin/special/private.go26
-rw-r--r--plugin/special/stdin.go28
-rw-r--r--plugin/special/stdout.go30
5 files changed, 71 insertions, 71 deletions
diff --git a/plugin/special/cutter.go b/plugin/special/cutter.go
index 2b33ee27..a96431e7 100644
--- a/plugin/special/cutter.go
+++ b/plugin/special/cutter.go
@@ -9,16 +9,16 @@ import (
)
const (
- typeCutter = "cutter"
- descCutter = "Remove data from previous steps"
+ TypeCutter = "cutter"
+ DescCutter = "Remove data from previous steps"
)
func init() {
- lib.RegisterInputConfigCreator(typeCutter, func(action lib.Action, data json.RawMessage) (lib.InputConverter, error) {
+ lib.RegisterInputConfigCreator(TypeCutter, func(action lib.Action, data json.RawMessage) (lib.InputConverter, error) {
return newCutter(action, data)
})
- lib.RegisterInputConverter(typeCutter, &cutter{
- Description: descCutter,
+ lib.RegisterInputConverter(TypeCutter, &Cutter{
+ Description: DescCutter,
})
}
@@ -35,7 +35,7 @@ func newCutter(action lib.Action, data json.RawMessage) (lib.InputConverter, err
}
if action != lib.ActionRemove {
- return nil, fmt.Errorf("❌ [type %s] only supports `remove` action", typeCutter)
+ return nil, fmt.Errorf("❌ [type %s] only supports `remove` action", TypeCutter)
}
// Filter want list
@@ -47,19 +47,19 @@ func newCutter(action lib.Action, data json.RawMessage) (lib.InputConverter, err
}
if len(wantList) == 0 {
- return nil, fmt.Errorf("❌ [type %s] wantedList must be specified", typeCutter)
+ return nil, fmt.Errorf("❌ [type %s] wantedList must be specified", TypeCutter)
}
- return &cutter{
- Type: typeCutter,
+ return &Cutter{
+ Type: TypeCutter,
Action: action,
- Description: descCutter,
+ Description: DescCutter,
Want: wantList,
OnlyIPType: tmp.OnlyIPType,
}, nil
}
-type cutter struct {
+type Cutter struct {
Type string
Action lib.Action
Description string
@@ -67,19 +67,19 @@ type cutter struct {
OnlyIPType lib.IPType
}
-func (c *cutter) GetType() string {
+func (c *Cutter) GetType() string {
return c.Type
}
-func (c *cutter) GetAction() lib.Action {
+func (c *Cutter) GetAction() lib.Action {
return c.Action
}
-func (c *cutter) GetDescription() string {
+func (c *Cutter) GetDescription() string {
return c.Description
}
-func (c *cutter) Input(container lib.Container) (lib.Container, error) {
+func (c *Cutter) Input(container lib.Container) (lib.Container, error) {
var ignoreIPType lib.IgnoreIPOption
switch c.OnlyIPType {
case lib.IPv4:
diff --git a/plugin/special/lookup.go b/plugin/special/lookup.go
index 6b9e6af0..96735146 100644
--- a/plugin/special/lookup.go
+++ b/plugin/special/lookup.go
@@ -12,16 +12,16 @@ import (
)
const (
- typeLookup = "lookup"
- descLookup = "Lookup specified IP or CIDR from various formats of data"
+ TypeLookup = "lookup"
+ DescLookup = "Lookup specified IP or CIDR from various formats of data"
)
func init() {
- lib.RegisterOutputConfigCreator(typeLookup, func(action lib.Action, data json.RawMessage) (lib.OutputConverter, error) {
+ lib.RegisterOutputConfigCreator(TypeLookup, func(action lib.Action, data json.RawMessage) (lib.OutputConverter, error) {
return newLookup(action, data)
})
- lib.RegisterOutputConverter(typeLookup, &lookup{
- Description: descLookup,
+ lib.RegisterOutputConverter(TypeLookup, &Lookup{
+ Description: DescLookup,
})
}
@@ -39,19 +39,19 @@ func newLookup(action lib.Action, data json.RawMessage) (lib.OutputConverter, er
tmp.Search = strings.TrimSpace(tmp.Search)
if tmp.Search == "" {
- return nil, fmt.Errorf("❌ [type %s | action %s] please specify an IP or a CIDR as search target", typeLookup, action)
+ return nil, fmt.Errorf("❌ [type %s | action %s] please specify an IP or a CIDR as search target", TypeLookup, action)
}
- return &lookup{
- Type: typeLookup,
+ return &Lookup{
+ Type: TypeLookup,
Action: action,
- Description: descLookup,
+ Description: DescLookup,
Search: tmp.Search,
SearchList: tmp.SearchList,
}, nil
}
-type lookup struct {
+type Lookup struct {
Type string
Action lib.Action
Description string
@@ -59,19 +59,19 @@ type lookup struct {
SearchList []string
}
-func (l *lookup) GetType() string {
+func (l *Lookup) GetType() string {
return l.Type
}
-func (l *lookup) GetAction() lib.Action {
+func (l *Lookup) GetAction() lib.Action {
return l.Action
}
-func (l *lookup) GetDescription() string {
+func (l *Lookup) GetDescription() string {
return l.Description
}
-func (l *lookup) Output(container lib.Container) error {
+func (l *Lookup) Output(container lib.Container) error {
switch strings.Contains(l.Search, "/") {
case true: // CIDR
if _, err := netip.ParsePrefix(l.Search); err != nil {
diff --git a/plugin/special/private.go b/plugin/special/private.go
index dc781c31..5c137687 100644
--- a/plugin/special/private.go
+++ b/plugin/special/private.go
@@ -8,8 +8,8 @@ import (
const (
entryNamePrivate = "private"
- typePrivate = "private"
- descPrivate = "Convert LAN and private network CIDR to other formats"
+ TypePrivate = "private"
+ DescPrivate = "Convert LAN and private network CIDR to other formats"
)
var privateCIDRs = []string{
@@ -37,11 +37,11 @@ var privateCIDRs = []string{
}
func init() {
- lib.RegisterInputConfigCreator(typePrivate, func(action lib.Action, data json.RawMessage) (lib.InputConverter, error) {
+ lib.RegisterInputConfigCreator(TypePrivate, func(action lib.Action, data json.RawMessage) (lib.InputConverter, error) {
return newPrivate(action, data)
})
- lib.RegisterInputConverter(typePrivate, &private{
- Description: descPrivate,
+ lib.RegisterInputConverter(TypePrivate, &Private{
+ Description: DescPrivate,
})
}
@@ -56,34 +56,34 @@ func newPrivate(action lib.Action, data json.RawMessage) (lib.InputConverter, er
}
}
- return &private{
- Type: typePrivate,
+ return &Private{
+ Type: TypePrivate,
Action: action,
- Description: descPrivate,
+ Description: DescPrivate,
OnlyIPType: tmp.OnlyIPType,
}, nil
}
-type private struct {
+type Private struct {
Type string
Action lib.Action
Description string
OnlyIPType lib.IPType
}
-func (p *private) GetType() string {
+func (p *Private) GetType() string {
return p.Type
}
-func (p *private) GetAction() lib.Action {
+func (p *Private) GetAction() lib.Action {
return p.Action
}
-func (p *private) GetDescription() string {
+func (p *Private) GetDescription() string {
return p.Description
}
-func (p *private) Input(container lib.Container) (lib.Container, error) {
+func (p *Private) Input(container lib.Container) (lib.Container, error) {
entry, found := container.GetEntry(entryNamePrivate)
if !found {
entry = lib.NewEntry(entryNamePrivate)
diff --git a/plugin/special/stdin.go b/plugin/special/stdin.go
index 1621c351..779a4cbd 100644
--- a/plugin/special/stdin.go
+++ b/plugin/special/stdin.go
@@ -11,16 +11,16 @@ import (
)
const (
- typeStdin = "stdin"
- descStdin = "Accept plaintext IP & CIDR from standard input, separated by newline"
+ TypeStdin = "stdin"
+ DescStdin = "Accept plaintext IP & CIDR from standard input, separated by newline"
)
func init() {
- lib.RegisterInputConfigCreator(typeStdin, func(action lib.Action, data json.RawMessage) (lib.InputConverter, error) {
+ lib.RegisterInputConfigCreator(TypeStdin, func(action lib.Action, data json.RawMessage) (lib.InputConverter, error) {
return newStdin(action, data)
})
- lib.RegisterInputConverter(typeStdin, &stdin{
- Description: descStdin,
+ lib.RegisterInputConverter(TypeStdin, &Stdin{
+ Description: DescStdin,
})
}
@@ -37,19 +37,19 @@ func newStdin(action lib.Action, data json.RawMessage) (lib.InputConverter, erro
}
if tmp.Name == "" {
- return nil, fmt.Errorf("❌ [type %s | action %s] missing name", typeStdin, action)
+ return nil, fmt.Errorf("❌ [type %s | action %s] missing name", TypeStdin, action)
}
- return &stdin{
- Type: typeStdin,
+ return &Stdin{
+ Type: TypeStdin,
Action: action,
- Description: descStdin,
+ Description: DescStdin,
Name: tmp.Name,
OnlyIPType: tmp.OnlyIPType,
}, nil
}
-type stdin struct {
+type Stdin struct {
Type string
Action lib.Action
Description string
@@ -57,19 +57,19 @@ type stdin struct {
OnlyIPType lib.IPType
}
-func (s *stdin) GetType() string {
+func (s *Stdin) GetType() string {
return s.Type
}
-func (s *stdin) GetAction() lib.Action {
+func (s *Stdin) GetAction() lib.Action {
return s.Action
}
-func (s *stdin) GetDescription() string {
+func (s *Stdin) GetDescription() string {
return s.Description
}
-func (s *stdin) Input(container lib.Container) (lib.Container, error) {
+func (s *Stdin) Input(container lib.Container) (lib.Container, error) {
entry := lib.NewEntry(s.Name)
scanner := bufio.NewScanner(os.Stdin)
diff --git a/plugin/special/stdout.go b/plugin/special/stdout.go
index 8c57cb58..ed8467ed 100644
--- a/plugin/special/stdout.go
+++ b/plugin/special/stdout.go
@@ -12,16 +12,16 @@ import (
)
const (
- typeStdout = "stdout"
- descStdout = "Convert data to plaintext CIDR format and output to standard output"
+ TypeStdout = "stdout"
+ DescStdout = "Convert data to plaintext CIDR format and output to standard output"
)
func init() {
- lib.RegisterOutputConfigCreator(typeStdout, func(action lib.Action, data json.RawMessage) (lib.OutputConverter, error) {
+ lib.RegisterOutputConfigCreator(TypeStdout, func(action lib.Action, data json.RawMessage) (lib.OutputConverter, error) {
return newStdout(action, data)
})
- lib.RegisterOutputConverter(typeStdout, &stdout{
- Description: descStdout,
+ lib.RegisterOutputConverter(TypeStdout, &Stdout{
+ Description: DescStdout,
})
}
@@ -38,17 +38,17 @@ func newStdout(action lib.Action, data json.RawMessage) (lib.OutputConverter, er
}
}
- return &stdout{
- Type: typeStdout,
+ return &Stdout{
+ Type: TypeStdout,
Action: action,
- Description: descStdout,
+ Description: DescStdout,
Want: tmp.Want,
Exclude: tmp.Exclude,
OnlyIPType: tmp.OnlyIPType,
}, nil
}
-type stdout struct {
+type Stdout struct {
Type string
Action lib.Action
Description string
@@ -57,19 +57,19 @@ type stdout struct {
OnlyIPType lib.IPType
}
-func (s *stdout) GetType() string {
+func (s *Stdout) GetType() string {
return s.Type
}
-func (s *stdout) GetAction() lib.Action {
+func (s *Stdout) GetAction() lib.Action {
return s.Action
}
-func (s *stdout) GetDescription() string {
+func (s *Stdout) GetDescription() string {
return s.Description
}
-func (s *stdout) Output(container lib.Container) error {
+func (s *Stdout) Output(container lib.Container) error {
for _, name := range s.filterAndSortList(container) {
entry, found := container.GetEntry(name)
if !found {
@@ -89,7 +89,7 @@ func (s *stdout) Output(container lib.Container) error {
return nil
}
-func (s *stdout) filterAndSortList(container lib.Container) []string {
+func (s *Stdout) filterAndSortList(container lib.Container) []string {
excludeMap := make(map[string]bool)
for _, exclude := range s.Exclude {
if exclude = strings.ToUpper(strings.TrimSpace(exclude)); exclude != "" {
@@ -125,7 +125,7 @@ func (s *stdout) filterAndSortList(container lib.Container) []string {
return list
}
-func (s *stdout) generateCIDRList(entry *lib.Entry) ([]string, error) {
+func (s *Stdout) generateCIDRList(entry *lib.Entry) ([]string, error) {
var entryList []string
var err error
switch s.OnlyIPType {