diff options
| author | copilot-swe-agent[bot] <[email protected]> | 2026-04-28 18:24:00 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-04-28 18:24:00 +0000 |
| commit | 8834c0be63ee88e0ad23fe621d5f5fe344b32089 (patch) | |
| tree | 49029d2fd927e8832d05420d1bf1cf850aa22325 /lookup.go | |
| parent | 4f125e579472e5ed87fd052ef68ab80f5fe679b0 (diff) | |
Refactor all plugins to use functional options patterncopilot/refactor-plugins-functional-options
Agent-Logs-Url: https://github.com/Loyalsoldier/geoip/sessions/e2b66c9a-3d01-490c-9b31-32109cfe4feb
Co-authored-by: Loyalsoldier <[email protected]>
Diffstat (limited to 'lookup.go')
| -rw-r--r-- | lookup.go | 131 |
1 files changed, 60 insertions, 71 deletions
@@ -163,38 +163,35 @@ func getInputForLookup(format, name, uri, dir string) lib.InputConverter { switch strings.ToLower(format) { case strings.ToLower(maxmind.TypeGeoLite2CountryMMDBIn): - input = &maxmind.GeoLite2CountryMMDBIn{ - Type: maxmind.TypeGeoLite2CountryMMDBIn, - Action: lib.ActionAdd, - Description: maxmind.DescGeoLite2CountryMMDBIn, - URI: uri, - } + input = maxmind.NewGeoLite2CountryMMDBIn( + maxmind.TypeGeoLite2CountryMMDBIn, + maxmind.DescGeoLite2CountryMMDBIn, + lib.ActionAdd, + maxmind.WithGeoLite2CountryMMDBInURI(maxmind.TypeGeoLite2CountryMMDBIn, uri), + ) case strings.ToLower(maxmind.TypeDBIPCountryMMDBIn): - input = &maxmind.GeoLite2CountryMMDBIn{ - Type: maxmind.TypeDBIPCountryMMDBIn, - Action: lib.ActionAdd, - Description: maxmind.DescDBIPCountryMMDBIn, - URI: uri, - } + input = maxmind.NewGeoLite2CountryMMDBIn( + maxmind.TypeDBIPCountryMMDBIn, + maxmind.DescDBIPCountryMMDBIn, + lib.ActionAdd, + maxmind.WithGeoLite2CountryMMDBInURI(maxmind.TypeDBIPCountryMMDBIn, uri), + ) case strings.ToLower(maxmind.TypeIPInfoCountryMMDBIn): - input = &maxmind.GeoLite2CountryMMDBIn{ - Type: maxmind.TypeIPInfoCountryMMDBIn, - Action: lib.ActionAdd, - Description: maxmind.DescIPInfoCountryMMDBIn, - URI: uri, - } + input = maxmind.NewGeoLite2CountryMMDBIn( + maxmind.TypeIPInfoCountryMMDBIn, + maxmind.DescIPInfoCountryMMDBIn, + lib.ActionAdd, + maxmind.WithGeoLite2CountryMMDBInURI(maxmind.TypeIPInfoCountryMMDBIn, uri), + ) case strings.ToLower(mihomo.TypeMRSIn): - input = &mihomo.MRSIn{ - Type: mihomo.TypeMRSIn, - Action: lib.ActionAdd, - Description: mihomo.DescMRSIn, - Name: name, - URI: uri, - InputDir: dir, - } + input = mihomo.NewMRSIn( + lib.ActionAdd, + mihomo.WithMRSInNameAndURI(name, uri), + mihomo.WithMRSInInputDir(dir), + ) case strings.ToLower(singbox.TypeSRSIn): input = singbox.NewSRSIn( @@ -204,52 +201,46 @@ func getInputForLookup(format, name, uri, dir string) lib.InputConverter { ) case strings.ToLower(v2ray.TypeGeoIPDatIn): - input = &v2ray.GeoIPDatIn{ - Type: v2ray.TypeGeoIPDatIn, - Action: lib.ActionAdd, - Description: v2ray.DescGeoIPDatIn, - URI: uri, - } + input = v2ray.NewGeoIPDatIn( + lib.ActionAdd, + v2ray.WithGeoIPDatInURI(uri), + ) case strings.ToLower(plaintext.TypeTextIn): - input = &plaintext.TextIn{ - Type: plaintext.TypeTextIn, - Action: lib.ActionAdd, - Description: plaintext.DescTextIn, - Name: name, - URI: uri, - InputDir: dir, - } + input = plaintext.NewTextIn( + plaintext.TypeTextIn, + plaintext.DescTextIn, + lib.ActionAdd, + plaintext.WithTextInInputDir(plaintext.TypeTextIn, dir), + plaintext.WithTextInNameAndURI(plaintext.TypeTextIn, name, uri), + ) case strings.ToLower(plaintext.TypeClashRuleSetIPCIDRIn): - input = &plaintext.TextIn{ - Type: plaintext.TypeClashRuleSetIPCIDRIn, - Action: lib.ActionAdd, - Description: plaintext.DescClashRuleSetIPCIDRIn, - Name: name, - URI: uri, - InputDir: dir, - } + input = plaintext.NewTextIn( + plaintext.TypeClashRuleSetIPCIDRIn, + plaintext.DescClashRuleSetIPCIDRIn, + lib.ActionAdd, + plaintext.WithTextInInputDir(plaintext.TypeClashRuleSetIPCIDRIn, dir), + plaintext.WithTextInNameAndURI(plaintext.TypeClashRuleSetIPCIDRIn, name, uri), + ) case strings.ToLower(plaintext.TypeClashRuleSetClassicalIn): - input = &plaintext.TextIn{ - Type: plaintext.TypeClashRuleSetClassicalIn, - Action: lib.ActionAdd, - Description: plaintext.DescClashRuleSetClassicalIn, - Name: name, - URI: uri, - InputDir: dir, - } + input = plaintext.NewTextIn( + plaintext.TypeClashRuleSetClassicalIn, + plaintext.DescClashRuleSetClassicalIn, + lib.ActionAdd, + plaintext.WithTextInInputDir(plaintext.TypeClashRuleSetClassicalIn, dir), + plaintext.WithTextInNameAndURI(plaintext.TypeClashRuleSetClassicalIn, name, uri), + ) case strings.ToLower(plaintext.TypeSurgeRuleSetIn): - input = &plaintext.TextIn{ - Type: plaintext.TypeSurgeRuleSetIn, - Action: lib.ActionAdd, - Description: plaintext.DescSurgeRuleSetIn, - Name: name, - URI: uri, - InputDir: dir, - } + input = plaintext.NewTextIn( + plaintext.TypeSurgeRuleSetIn, + plaintext.DescSurgeRuleSetIn, + lib.ActionAdd, + plaintext.WithTextInInputDir(plaintext.TypeSurgeRuleSetIn, dir), + plaintext.WithTextInNameAndURI(plaintext.TypeSurgeRuleSetIn, name, uri), + ) default: log.Fatal("unsupported input format") @@ -259,11 +250,9 @@ func getInputForLookup(format, name, uri, dir string) lib.InputConverter { } func getOutputForLookup(search string, searchList ...string) lib.OutputConverter { - return &special.Lookup{ - Type: special.TypeLookup, - Action: lib.ActionOutput, - Description: special.DescLookup, - Search: search, - SearchList: searchList, - } + return special.NewLookup( + lib.ActionOutput, + special.WithLookupSearch(search), + special.WithLookupSearchList(searchList), + ) } |
