summaryrefslogtreecommitdiff
path: root/plugin/special/cutter.go
diff options
context:
space:
mode:
authorcopilot-swe-agent[bot] <[email protected]>2026-03-09 06:35:47 +0000
committercopilot-swe-agent[bot] <[email protected]>2026-03-09 06:35:47 +0000
commit2600825c50d7e7f2b4427674f1aefca270bcca27 (patch)
tree18f216c6af28fd3975a0665d75ccf7b5c0078cb6 /plugin/special/cutter.go
parent5a14eb90f575b983aa407341af91aa7654e65f12 (diff)
Refactor: all plugin subdirectories use option patterncopilot/modify-plugin-files-subdirectories
Apply the same functional options pattern from plugin/singbox to: - plugin/mihomo (mrs_in.go, mrs_out.go) - plugin/plaintext (text_in.go, common_in.go, common_out.go, text_out.go, clash_in.go, clash_out.go, json_in.go, surge_in.go, surge_out.go) - plugin/maxmind (all input/output files) - plugin/v2ray (dat_in.go, dat_out.go) - plugin/special (cutter.go, lookup.go, private.go, stdin.go, stdout.go) - lookup.go and merge.go updated to use new constructors Co-authored-by: Loyalsoldier <[email protected]>
Diffstat (limited to 'plugin/special/cutter.go')
-rw-r--r--plugin/special/cutter.go66
1 files changed, 46 insertions, 20 deletions
diff --git a/plugin/special/cutter.go b/plugin/special/cutter.go
index 509cddbb..babeac5c 100644
--- a/plugin/special/cutter.go
+++ b/plugin/special/cutter.go
@@ -15,14 +15,38 @@ const (
func init() {
lib.RegisterInputConfigCreator(TypeCutter, func(action lib.Action, data json.RawMessage) (lib.InputConverter, error) {
- return newCutter(action, data)
+ return NewCutterFromBytes(action, data)
})
- lib.RegisterInputConverter(TypeCutter, &Cutter{
+ lib.RegisterInputConverter(TypeCutter, &cutter{
Description: DescCutter,
})
}
-func newCutter(action lib.Action, data json.RawMessage) (lib.InputConverter, error) {
+type cutter struct {
+ Type string
+ Action lib.Action
+ Description string
+ Want map[string]bool
+ OnlyIPType lib.IPType
+}
+
+func NewCutter(action lib.Action, opts ...lib.InputOption) lib.InputConverter {
+ c := &cutter{
+ Type: TypeCutter,
+ Action: action,
+ Description: DescCutter,
+ }
+
+ for _, opt := range opts {
+ if opt != nil {
+ opt(c)
+ }
+ }
+
+ return c
+}
+
+func NewCutterFromBytes(action lib.Action, data []byte) (lib.InputConverter, error) {
var tmp struct {
Want []string `json:"wantedList"`
OnlyIPType lib.IPType `json:"onlyIPType"`
@@ -50,36 +74,38 @@ func newCutter(action lib.Action, data json.RawMessage) (lib.InputConverter, err
return nil, fmt.Errorf("❌ [type %s] wantedList must be specified", TypeCutter)
}
- return &Cutter{
- Type: TypeCutter,
- Action: action,
- Description: DescCutter,
- Want: wantList,
- OnlyIPType: tmp.OnlyIPType,
- }, nil
+ return NewCutter(
+ action,
+ WithCutterWantedList(wantList),
+ WithCutterOnlyIPType(tmp.OnlyIPType),
+ ), nil
}
-type Cutter struct {
- Type string
- Action lib.Action
- Description string
- Want map[string]bool
- OnlyIPType lib.IPType
+func WithCutterWantedList(wantList map[string]bool) lib.InputOption {
+ return func(c lib.InputConverter) {
+ c.(*cutter).Want = wantList
+ }
+}
+
+func WithCutterOnlyIPType(onlyIPType lib.IPType) lib.InputOption {
+ return func(c lib.InputConverter) {
+ c.(*cutter).OnlyIPType = onlyIPType
+ }
}
-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) {
ignoreIPType := lib.GetIgnoreIPType(c.OnlyIPType)
for entry := range container.Loop() {