diff options
| author | copilot-swe-agent[bot] <[email protected]> | 2026-03-09 06:35:47 +0000 |
|---|---|---|
| committer | copilot-swe-agent[bot] <[email protected]> | 2026-03-09 06:35:47 +0000 |
| commit | 2600825c50d7e7f2b4427674f1aefca270bcca27 (patch) | |
| tree | 18f216c6af28fd3975a0665d75ccf7b5c0078cb6 /plugin/maxmind/maxmind_asn_csv_in.go | |
| parent | 5a14eb90f575b983aa407341af91aa7654e65f12 (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/maxmind/maxmind_asn_csv_in.go')
| -rw-r--r-- | plugin/maxmind/maxmind_asn_csv_in.go | 92 |
1 files changed, 65 insertions, 27 deletions
diff --git a/plugin/maxmind/maxmind_asn_csv_in.go b/plugin/maxmind/maxmind_asn_csv_in.go index d924e3f9..43a4ff11 100644 --- a/plugin/maxmind/maxmind_asn_csv_in.go +++ b/plugin/maxmind/maxmind_asn_csv_in.go @@ -24,14 +24,64 @@ var ( func init() { lib.RegisterInputConfigCreator(TypeGeoLite2ASNCSVIn, func(action lib.Action, data json.RawMessage) (lib.InputConverter, error) { - return newGeoLite2ASNCSVIn(action, data) + return NewGeoLite2ASNCSVInFromBytes(action, data) }) - lib.RegisterInputConverter(TypeGeoLite2ASNCSVIn, &GeoLite2ASNCSVIn{ + lib.RegisterInputConverter(TypeGeoLite2ASNCSVIn, &geoLite2ASNCSVIn{ Description: DescGeoLite2ASNCSVIn, }) } -func newGeoLite2ASNCSVIn(action lib.Action, data json.RawMessage) (lib.InputConverter, error) { +type geoLite2ASNCSVIn struct { + Type string + Action lib.Action + Description string + IPv4File string + IPv6File string + Want map[string][]string + OnlyIPType lib.IPType +} + +func NewGeoLite2ASNCSVIn(action lib.Action, opts ...lib.InputOption) lib.InputConverter { + g := &geoLite2ASNCSVIn{ + Type: TypeGeoLite2ASNCSVIn, + Action: action, + Description: DescGeoLite2ASNCSVIn, + } + + for _, opt := range opts { + if opt != nil { + opt(g) + } + } + + return g +} + +func WithASNIPv4File(file string) lib.InputOption { + return func(g lib.InputConverter) { + g.(*geoLite2ASNCSVIn).IPv4File = strings.TrimSpace(file) + } +} + +func WithASNIPv6File(file string) lib.InputOption { + return func(g lib.InputConverter) { + g.(*geoLite2ASNCSVIn).IPv6File = strings.TrimSpace(file) + } +} + +func WithASNWantedList(wantList map[string][]string) lib.InputOption { + return func(g lib.InputConverter) { + g.(*geoLite2ASNCSVIn).Want = wantList + } +} + +func WithASNOnlyIPType(onlyIPType lib.IPType) lib.InputOption { + return func(g lib.InputConverter) { + g.(*geoLite2ASNCSVIn).OnlyIPType = onlyIPType + } +} + +func NewGeoLite2ASNCSVInFromBytes(action lib.Action, data []byte) (lib.InputConverter, error) { var tmp struct { IPv4File string `json:"ipv4"` IPv6File string `json:"ipv6"` @@ -85,40 +135,28 @@ func newGeoLite2ASNCSVIn(action lib.Action, data json.RawMessage) (lib.InputConv wantList[asn] = []string{"AS" + asn} } - return &GeoLite2ASNCSVIn{ - Type: TypeGeoLite2ASNCSVIn, - Action: action, - Description: DescGeoLite2ASNCSVIn, - IPv4File: tmp.IPv4File, - IPv6File: tmp.IPv6File, - Want: wantList, - OnlyIPType: tmp.OnlyIPType, - }, nil -} - -type GeoLite2ASNCSVIn struct { - Type string - Action lib.Action - Description string - IPv4File string - IPv6File string - Want map[string][]string - OnlyIPType lib.IPType + return NewGeoLite2ASNCSVIn( + action, + WithASNIPv4File(tmp.IPv4File), + WithASNIPv6File(tmp.IPv6File), + WithASNWantedList(wantList), + WithASNOnlyIPType(tmp.OnlyIPType), + ), nil } -func (g *GeoLite2ASNCSVIn) GetType() string { +func (g *geoLite2ASNCSVIn) GetType() string { return g.Type } -func (g *GeoLite2ASNCSVIn) GetAction() lib.Action { +func (g *geoLite2ASNCSVIn) GetAction() lib.Action { return g.Action } -func (g *GeoLite2ASNCSVIn) GetDescription() string { +func (g *geoLite2ASNCSVIn) GetDescription() string { return g.Description } -func (g *GeoLite2ASNCSVIn) Input(container lib.Container) (lib.Container, error) { +func (g *geoLite2ASNCSVIn) Input(container lib.Container) (lib.Container, error) { entries := make(map[string]*lib.Entry) if g.IPv4File != "" { @@ -157,7 +195,7 @@ func (g *GeoLite2ASNCSVIn) Input(container lib.Container) (lib.Container, error) return container, nil } -func (g *GeoLite2ASNCSVIn) process(file string, entries map[string]*lib.Entry) error { +func (g *geoLite2ASNCSVIn) process(file string, entries map[string]*lib.Entry) error { if entries == nil { entries = make(map[string]*lib.Entry) } |
