diff --git a/lookup.go b/lookup.go index 442229c7a44..15ffd3e94c1 100644 --- a/lookup.go +++ b/lookup.go @@ -162,16 +162,16 @@ func getInputForLookup(format, name, uri, dir string) lib.InputConverter { var input lib.InputConverter switch strings.ToLower(format) { - case strings.ToLower(maxmind.TypeMaxmindMMDBIn): - input = &maxmind.MMDBIn{ - Type: maxmind.TypeMaxmindMMDBIn, + case strings.ToLower(maxmind.TypeGeoLite2CountryMMDBIn): + input = &maxmind.GeoLite2CountryMMDBIn{ + Type: maxmind.TypeGeoLite2CountryMMDBIn, Action: lib.ActionAdd, - Description: maxmind.DescMaxmindMMDBIn, + Description: maxmind.DescGeoLite2CountryMMDBIn, URI: uri, } case strings.ToLower(maxmind.TypeDBIPCountryMMDBIn): - input = &maxmind.MMDBIn{ + input = &maxmind.GeoLite2CountryMMDBIn{ Type: maxmind.TypeDBIPCountryMMDBIn, Action: lib.ActionAdd, Description: maxmind.DescDBIPCountryMMDBIn, @@ -179,7 +179,7 @@ func getInputForLookup(format, name, uri, dir string) lib.InputConverter { } case strings.ToLower(maxmind.TypeIPInfoCountryMMDBIn): - input = &maxmind.MMDBIn{ + input = &maxmind.GeoLite2CountryMMDBIn{ Type: maxmind.TypeIPInfoCountryMMDBIn, Action: lib.ActionAdd, Description: maxmind.DescIPInfoCountryMMDBIn, @@ -206,11 +206,11 @@ func getInputForLookup(format, name, uri, dir string) lib.InputConverter { InputDir: dir, } - case strings.ToLower(v2ray.TypeGeoIPdatIn): + case strings.ToLower(v2ray.TypeGeoIPDatIn): input = &v2ray.GeoIPDatIn{ - Type: v2ray.TypeGeoIPdatIn, + Type: v2ray.TypeGeoIPDatIn, Action: lib.ActionAdd, - Description: v2ray.DescGeoIPdatIn, + Description: v2ray.DescGeoIPDatIn, URI: uri, } @@ -228,7 +228,7 @@ func getInputForLookup(format, name, uri, dir string) lib.InputConverter { input = &plaintext.TextIn{ Type: plaintext.TypeClashRuleSetIPCIDRIn, Action: lib.ActionAdd, - Description: plaintext.DescClashRuleSetIn, + Description: plaintext.DescClashRuleSetIPCIDRIn, Name: name, URI: uri, InputDir: dir, @@ -238,7 +238,7 @@ func getInputForLookup(format, name, uri, dir string) lib.InputConverter { input = &plaintext.TextIn{ Type: plaintext.TypeClashRuleSetClassicalIn, Action: lib.ActionAdd, - Description: plaintext.DescClashClassicalIn, + Description: plaintext.DescClashRuleSetClassicalIn, Name: name, URI: uri, InputDir: dir, diff --git a/plugin/maxmind/common_in.go b/plugin/maxmind/common_in.go index 0bf61e51fcd..3d97388c79e 100644 --- a/plugin/maxmind/common_in.go +++ b/plugin/maxmind/common_in.go @@ -9,12 +9,12 @@ import ( ) var ( - defaultGeoLite2MMDBFile = filepath.Join("./", "geolite2", "GeoLite2-Country.mmdb") - defaultDBIPCountryMMDBFile = filepath.Join("./", "db-ip", "dbip-country-lite.mmdb") - defaultIPInfoCountryMMDBFile = filepath.Join("./", "ipinfo", "country.mmdb") + defaultGeoLite2CountryMMDBFile = filepath.Join("./", "geolite2", "GeoLite2-Country.mmdb") + defaultDBIPCountryMMDBFile = filepath.Join("./", "db-ip", "dbip-country-lite.mmdb") + defaultIPInfoCountryMMDBFile = filepath.Join("./", "ipinfo", "country.mmdb") ) -func newMMDBIn(iType string, iDesc string, action lib.Action, data json.RawMessage) (lib.InputConverter, error) { +func newGeoLite2CountryMMDBIn(iType string, iDesc string, action lib.Action, data json.RawMessage) (lib.InputConverter, error) { var tmp struct { URI string `json:"uri"` Want []string `json:"wantedList"` @@ -29,8 +29,8 @@ func newMMDBIn(iType string, iDesc string, action lib.Action, data json.RawMessa if tmp.URI == "" { switch iType { - case TypeMaxmindMMDBIn: - tmp.URI = defaultGeoLite2MMDBFile + case TypeGeoLite2CountryMMDBIn: + tmp.URI = defaultGeoLite2CountryMMDBFile case TypeDBIPCountryMMDBIn: tmp.URI = defaultDBIPCountryMMDBFile @@ -48,7 +48,7 @@ func newMMDBIn(iType string, iDesc string, action lib.Action, data json.RawMessa } } - return &MMDBIn{ + return &GeoLite2CountryMMDBIn{ Type: iType, Action: action, Description: iDesc, diff --git a/plugin/maxmind/common_out.go b/plugin/maxmind/common_out.go index ad5edce6450..bfd41aaa322 100644 --- a/plugin/maxmind/common_out.go +++ b/plugin/maxmind/common_out.go @@ -13,13 +13,14 @@ import ( ) var ( - defaultOutputName = "Country.mmdb" + defaultGeoLite2CountryMMDBOutputName = "Country.mmdb" + defaultMaxmindOutputDir = filepath.Join("./", "output", "maxmind") defaultDBIPOutputDir = filepath.Join("./", "output", "db-ip") defaultIPInfoOutputDir = filepath.Join("./", "output", "ipinfo") ) -func newMMDBOut(iType string, iDesc string, action lib.Action, data json.RawMessage) (lib.OutputConverter, error) { +func newGeoLite2CountryMMDBOut(iType string, iDesc string, action lib.Action, data json.RawMessage) (lib.OutputConverter, error) { var tmp struct { OutputName string `json:"outputName"` OutputDir string `json:"outputDir"` @@ -38,12 +39,12 @@ func newMMDBOut(iType string, iDesc string, action lib.Action, data json.RawMess } if tmp.OutputName == "" { - tmp.OutputName = defaultOutputName + tmp.OutputName = defaultGeoLite2CountryMMDBOutputName } if tmp.OutputDir == "" { switch iType { - case TypeMaxmindMMDBOut: + case TypeGeoLite2CountryMMDBOut: tmp.OutputDir = defaultMaxmindOutputDir case TypeDBIPCountryMMDBOut: @@ -54,7 +55,7 @@ func newMMDBOut(iType string, iDesc string, action lib.Action, data json.RawMess } } - return &MMDBOut{ + return &GeoLite2CountryMMDBOut{ Type: iType, Action: action, Description: iDesc, @@ -69,18 +70,18 @@ func newMMDBOut(iType string, iDesc string, action lib.Action, data json.RawMess }, nil } -func (m *MMDBOut) GetExtraInfo() (map[string]interface{}, error) { - if strings.TrimSpace(m.SourceMMDBURI) == "" { +func (g *GeoLite2CountryMMDBOut) GetExtraInfo() (map[string]any, error) { + if strings.TrimSpace(g.SourceMMDBURI) == "" { return nil, nil } var content []byte var err error switch { - case strings.HasPrefix(strings.ToLower(m.SourceMMDBURI), "http://"), strings.HasPrefix(strings.ToLower(m.SourceMMDBURI), "https://"): - content, err = lib.GetRemoteURLContent(m.SourceMMDBURI) + case strings.HasPrefix(strings.ToLower(g.SourceMMDBURI), "http://"), strings.HasPrefix(strings.ToLower(g.SourceMMDBURI), "https://"): + content, err = lib.GetRemoteURLContent(g.SourceMMDBURI) default: - content, err = os.ReadFile(m.SourceMMDBURI) + content, err = os.ReadFile(g.SourceMMDBURI) } if err != nil { return nil, err @@ -92,11 +93,11 @@ func (m *MMDBOut) GetExtraInfo() (map[string]interface{}, error) { } defer db.Close() - infoList := make(map[string]interface{}) + infoList := make(map[string]any) networks := db.Networks(maxminddb.SkipAliasedNetworks) for networks.Next() { - switch m.Type { - case TypeMaxmindMMDBOut, TypeDBIPCountryMMDBOut: + switch g.Type { + case TypeGeoLite2CountryMMDBOut, TypeDBIPCountryMMDBOut: var record geoip2.Country _, err := networks.Network(&record) if err != nil { @@ -170,7 +171,7 @@ func (m *MMDBOut) GetExtraInfo() (map[string]interface{}, error) { } if len(infoList) == 0 { - return nil, fmt.Errorf("❌ [type %s | action %s] no extra info found in the source MMDB file: %s", m.Type, m.Action, m.SourceMMDBURI) + return nil, fmt.Errorf("❌ [type %s | action %s] no extra info found in the source MMDB file: %s", g.Type, g.Action, g.SourceMMDBURI) } return infoList, nil diff --git a/plugin/maxmind/dbip_country_mmdb_in.go b/plugin/maxmind/dbip_country_mmdb_in.go index b23e753c50f..304f29e54a4 100644 --- a/plugin/maxmind/dbip_country_mmdb_in.go +++ b/plugin/maxmind/dbip_country_mmdb_in.go @@ -18,9 +18,9 @@ const ( func init() { lib.RegisterInputConfigCreator(TypeDBIPCountryMMDBIn, func(action lib.Action, data json.RawMessage) (lib.InputConverter, error) { - return newMMDBIn(TypeDBIPCountryMMDBIn, DescDBIPCountryMMDBIn, action, data) + return newGeoLite2CountryMMDBIn(TypeDBIPCountryMMDBIn, DescDBIPCountryMMDBIn, action, data) }) - lib.RegisterInputConverter(TypeDBIPCountryMMDBIn, &MMDBIn{ + lib.RegisterInputConverter(TypeDBIPCountryMMDBIn, &GeoLite2CountryMMDBIn{ Description: DescDBIPCountryMMDBIn, }) } diff --git a/plugin/maxmind/dbip_country_mmdb_out.go b/plugin/maxmind/dbip_country_mmdb_out.go index e60a3adf130..77857d95224 100644 --- a/plugin/maxmind/dbip_country_mmdb_out.go +++ b/plugin/maxmind/dbip_country_mmdb_out.go @@ -18,9 +18,9 @@ const ( func init() { lib.RegisterOutputConfigCreator(TypeDBIPCountryMMDBOut, func(action lib.Action, data json.RawMessage) (lib.OutputConverter, error) { - return newMMDBOut(TypeDBIPCountryMMDBOut, DescDBIPCountryMMDBOut, action, data) + return newGeoLite2CountryMMDBOut(TypeDBIPCountryMMDBOut, DescDBIPCountryMMDBOut, action, data) }) - lib.RegisterOutputConverter(TypeDBIPCountryMMDBOut, &MMDBOut{ + lib.RegisterOutputConverter(TypeDBIPCountryMMDBOut, &GeoLite2CountryMMDBOut{ Description: DescDBIPCountryMMDBOut, }) } diff --git a/plugin/maxmind/ipinfo_country_mmdb_in.go b/plugin/maxmind/ipinfo_country_mmdb_in.go index 4e7b1a5cf2c..8551e4535ea 100644 --- a/plugin/maxmind/ipinfo_country_mmdb_in.go +++ b/plugin/maxmind/ipinfo_country_mmdb_in.go @@ -18,9 +18,9 @@ const ( func init() { lib.RegisterInputConfigCreator(TypeIPInfoCountryMMDBIn, func(action lib.Action, data json.RawMessage) (lib.InputConverter, error) { - return newMMDBIn(TypeIPInfoCountryMMDBIn, DescIPInfoCountryMMDBIn, action, data) + return newGeoLite2CountryMMDBIn(TypeIPInfoCountryMMDBIn, DescIPInfoCountryMMDBIn, action, data) }) - lib.RegisterInputConverter(TypeIPInfoCountryMMDBIn, &MMDBIn{ + lib.RegisterInputConverter(TypeIPInfoCountryMMDBIn, &GeoLite2CountryMMDBIn{ Description: DescIPInfoCountryMMDBIn, }) } diff --git a/plugin/maxmind/ipinfo_country_mmdb_out.go b/plugin/maxmind/ipinfo_country_mmdb_out.go index ac9e5a343fe..bed18af74b6 100644 --- a/plugin/maxmind/ipinfo_country_mmdb_out.go +++ b/plugin/maxmind/ipinfo_country_mmdb_out.go @@ -18,9 +18,9 @@ const ( func init() { lib.RegisterOutputConfigCreator(TypeIPInfoCountryMMDBOut, func(action lib.Action, data json.RawMessage) (lib.OutputConverter, error) { - return newMMDBOut(TypeIPInfoCountryMMDBOut, DescIPInfoCountryMMDBOut, action, data) + return newGeoLite2CountryMMDBOut(TypeIPInfoCountryMMDBOut, DescIPInfoCountryMMDBOut, action, data) }) - lib.RegisterOutputConverter(TypeIPInfoCountryMMDBOut, &MMDBOut{ + lib.RegisterOutputConverter(TypeIPInfoCountryMMDBOut, &GeoLite2CountryMMDBOut{ Description: DescIPInfoCountryMMDBOut, }) } diff --git a/plugin/maxmind/maxmind_asn_csv_in.go b/plugin/maxmind/maxmind_asn_csv_in.go index 8c8c3fe2339..5b42be59777 100644 --- a/plugin/maxmind/maxmind_asn_csv_in.go +++ b/plugin/maxmind/maxmind_asn_csv_in.go @@ -13,25 +13,25 @@ import ( ) const ( - TypeASNCSV = "maxmindGeoLite2ASNCSV" - DescASNCSV = "Convert MaxMind GeoLite2 ASN CSV data to other formats" + TypeGeoLite2ASNCSVIn = "maxmindGeoLite2ASNCSV" + DescGeoLite2ASNCSVIn = "Convert MaxMind GeoLite2 ASN CSV data to other formats" ) var ( - defaultASNIPv4File = filepath.Join("./", "geolite2", "GeoLite2-ASN-Blocks-IPv4.csv") - defaultASNIPv6File = filepath.Join("./", "geolite2", "GeoLite2-ASN-Blocks-IPv6.csv") + defaultGeoLite2ASNCSVIPv4File = filepath.Join("./", "geolite2", "GeoLite2-ASN-Blocks-IPv4.csv") + defaultGeoLite2ASNCSVIPv6File = filepath.Join("./", "geolite2", "GeoLite2-ASN-Blocks-IPv6.csv") ) func init() { - lib.RegisterInputConfigCreator(TypeASNCSV, func(action lib.Action, data json.RawMessage) (lib.InputConverter, error) { - return newGeoLite2ASNCSV(action, data) + lib.RegisterInputConfigCreator(TypeGeoLite2ASNCSVIn, func(action lib.Action, data json.RawMessage) (lib.InputConverter, error) { + return newGeoLite2ASNCSVIn(action, data) }) - lib.RegisterInputConverter(TypeASNCSV, &GeoLite2ASNCSV{ - Description: DescASNCSV, + lib.RegisterInputConverter(TypeGeoLite2ASNCSVIn, &GeoLite2ASNCSVIn{ + Description: DescGeoLite2ASNCSVIn, }) } -func newGeoLite2ASNCSV(action lib.Action, data json.RawMessage) (lib.InputConverter, error) { +func newGeoLite2ASNCSVIn(action lib.Action, data json.RawMessage) (lib.InputConverter, error) { var tmp struct { IPv4File string `json:"ipv4"` IPv6File string `json:"ipv6"` @@ -48,8 +48,8 @@ func newGeoLite2ASNCSV(action lib.Action, data json.RawMessage) (lib.InputConver // When both of IP files are not specified, // it means user wants to use the default ones if tmp.IPv4File == "" && tmp.IPv6File == "" { - tmp.IPv4File = defaultASNIPv4File - tmp.IPv6File = defaultASNIPv6File + tmp.IPv4File = defaultGeoLite2ASNCSVIPv4File + tmp.IPv6File = defaultGeoLite2ASNCSVIPv6File } // Filter want list @@ -85,10 +85,10 @@ func newGeoLite2ASNCSV(action lib.Action, data json.RawMessage) (lib.InputConver wantList[asn] = []string{"AS" + asn} } - return &GeoLite2ASNCSV{ - Type: TypeASNCSV, + return &GeoLite2ASNCSVIn{ + Type: TypeGeoLite2ASNCSVIn, Action: action, - Description: DescASNCSV, + Description: DescGeoLite2ASNCSVIn, IPv4File: tmp.IPv4File, IPv6File: tmp.IPv6File, Want: wantList, @@ -96,7 +96,7 @@ func newGeoLite2ASNCSV(action lib.Action, data json.RawMessage) (lib.InputConver }, nil } -type GeoLite2ASNCSV struct { +type GeoLite2ASNCSVIn struct { Type string Action lib.Action Description string @@ -106,19 +106,19 @@ type GeoLite2ASNCSV struct { OnlyIPType lib.IPType } -func (g *GeoLite2ASNCSV) GetType() string { +func (g *GeoLite2ASNCSVIn) GetType() string { return g.Type } -func (g *GeoLite2ASNCSV) GetAction() lib.Action { +func (g *GeoLite2ASNCSVIn) GetAction() lib.Action { return g.Action } -func (g *GeoLite2ASNCSV) GetDescription() string { +func (g *GeoLite2ASNCSVIn) GetDescription() string { return g.Description } -func (g *GeoLite2ASNCSV) 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 != "" { @@ -163,7 +163,7 @@ func (g *GeoLite2ASNCSV) Input(container lib.Container) (lib.Container, error) { return container, nil } -func (g *GeoLite2ASNCSV) 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) } diff --git a/plugin/maxmind/maxmind_country_csv_in.go b/plugin/maxmind/maxmind_country_csv_in.go index 366220abd79..da70c281519 100644 --- a/plugin/maxmind/maxmind_country_csv_in.go +++ b/plugin/maxmind/maxmind_country_csv_in.go @@ -13,26 +13,26 @@ import ( ) const ( - TypeCountryCSV = "maxmindGeoLite2CountryCSV" - DescCountryCSV = "Convert MaxMind GeoLite2 country CSV data to other formats" + TypeGeoLite2CountryCSVIn = "maxmindGeoLite2CountryCSV" + DescGeoLite2CountryCSVIn = "Convert MaxMind GeoLite2 country CSV data to other formats" ) var ( - defaultCCFile = filepath.Join("./", "geolite2", "GeoLite2-Country-Locations-en.csv") - defaultCountryIPv4File = filepath.Join("./", "geolite2", "GeoLite2-Country-Blocks-IPv4.csv") - defaultCountryIPv6File = filepath.Join("./", "geolite2", "GeoLite2-Country-Blocks-IPv6.csv") + defaultGeoLite2CountryCodeFile = filepath.Join("./", "geolite2", "GeoLite2-Country-Locations-en.csv") + defaultGeoLite2CountryIPv4File = filepath.Join("./", "geolite2", "GeoLite2-Country-Blocks-IPv4.csv") + defaultGeoLite2CountryIPv6File = filepath.Join("./", "geolite2", "GeoLite2-Country-Blocks-IPv6.csv") ) func init() { - lib.RegisterInputConfigCreator(TypeCountryCSV, func(action lib.Action, data json.RawMessage) (lib.InputConverter, error) { - return newGeoLite2CountryCSV(action, data) + lib.RegisterInputConfigCreator(TypeGeoLite2CountryCSVIn, func(action lib.Action, data json.RawMessage) (lib.InputConverter, error) { + return newGeoLite2CountryCSVIn(action, data) }) - lib.RegisterInputConverter(TypeCountryCSV, &GeoLite2CountryCSV{ - Description: DescCountryCSV, + lib.RegisterInputConverter(TypeGeoLite2CountryCSVIn, &GeoLite2CountryCSVIn{ + Description: DescGeoLite2CountryCSVIn, }) } -func newGeoLite2CountryCSV(action lib.Action, data json.RawMessage) (lib.InputConverter, error) { +func newGeoLite2CountryCSVIn(action lib.Action, data json.RawMessage) (lib.InputConverter, error) { var tmp struct { CountryCodeFile string `json:"country"` IPv4File string `json:"ipv4"` @@ -48,14 +48,14 @@ func newGeoLite2CountryCSV(action lib.Action, data json.RawMessage) (lib.InputCo } if tmp.CountryCodeFile == "" { - tmp.CountryCodeFile = defaultCCFile + tmp.CountryCodeFile = defaultGeoLite2CountryCodeFile } // When both of IP files are not specified, // it means user wants to use the default ones if tmp.IPv4File == "" && tmp.IPv6File == "" { - tmp.IPv4File = defaultCountryIPv4File - tmp.IPv6File = defaultCountryIPv6File + tmp.IPv4File = defaultGeoLite2CountryIPv4File + tmp.IPv6File = defaultGeoLite2CountryIPv6File } // Filter want list @@ -66,10 +66,10 @@ func newGeoLite2CountryCSV(action lib.Action, data json.RawMessage) (lib.InputCo } } - return &GeoLite2CountryCSV{ - Type: TypeCountryCSV, + return &GeoLite2CountryCSVIn{ + Type: TypeGeoLite2CountryCSVIn, Action: action, - Description: DescCountryCSV, + Description: DescGeoLite2CountryCSVIn, CountryCodeFile: tmp.CountryCodeFile, IPv4File: tmp.IPv4File, IPv6File: tmp.IPv6File, @@ -78,7 +78,7 @@ func newGeoLite2CountryCSV(action lib.Action, data json.RawMessage) (lib.InputCo }, nil } -type GeoLite2CountryCSV struct { +type GeoLite2CountryCSVIn struct { Type string Action lib.Action Description string @@ -89,19 +89,19 @@ type GeoLite2CountryCSV struct { OnlyIPType lib.IPType } -func (g *GeoLite2CountryCSV) GetType() string { +func (g *GeoLite2CountryCSVIn) GetType() string { return g.Type } -func (g *GeoLite2CountryCSV) GetAction() lib.Action { +func (g *GeoLite2CountryCSVIn) GetAction() lib.Action { return g.Action } -func (g *GeoLite2CountryCSV) GetDescription() string { +func (g *GeoLite2CountryCSVIn) GetDescription() string { return g.Description } -func (g *GeoLite2CountryCSV) Input(container lib.Container) (lib.Container, error) { +func (g *GeoLite2CountryCSVIn) Input(container lib.Container) (lib.Container, error) { ccMap, err := g.getCountryCode() if err != nil { return nil, err @@ -151,7 +151,7 @@ func (g *GeoLite2CountryCSV) Input(container lib.Container) (lib.Container, erro return container, nil } -func (g *GeoLite2CountryCSV) getCountryCode() (map[string]string, error) { +func (g *GeoLite2CountryCSVIn) getCountryCode() (map[string]string, error) { var f io.ReadCloser var err error switch { @@ -198,7 +198,7 @@ func (g *GeoLite2CountryCSV) getCountryCode() (map[string]string, error) { return ccMap, nil } -func (g *GeoLite2CountryCSV) process(file string, ccMap map[string]string, entries map[string]*lib.Entry) error { +func (g *GeoLite2CountryCSVIn) process(file string, ccMap map[string]string, entries map[string]*lib.Entry) error { if len(ccMap) == 0 { return fmt.Errorf("❌ [type %s | action %s] invalid country code data", g.Type, g.Action) } diff --git a/plugin/maxmind/maxmind_country_mmdb_in.go b/plugin/maxmind/maxmind_country_mmdb_in.go index d69acbdc1a0..7578ba238e2 100644 --- a/plugin/maxmind/maxmind_country_mmdb_in.go +++ b/plugin/maxmind/maxmind_country_mmdb_in.go @@ -13,20 +13,20 @@ import ( ) const ( - TypeMaxmindMMDBIn = "maxmindMMDB" - DescMaxmindMMDBIn = "Convert MaxMind mmdb database to other formats" + TypeGeoLite2CountryMMDBIn = "maxmindMMDB" + DescGeoLite2CountryMMDBIn = "Convert MaxMind mmdb database to other formats" ) func init() { - lib.RegisterInputConfigCreator(TypeMaxmindMMDBIn, func(action lib.Action, data json.RawMessage) (lib.InputConverter, error) { - return newMMDBIn(TypeMaxmindMMDBIn, DescMaxmindMMDBIn, action, data) + lib.RegisterInputConfigCreator(TypeGeoLite2CountryMMDBIn, func(action lib.Action, data json.RawMessage) (lib.InputConverter, error) { + return newGeoLite2CountryMMDBIn(TypeGeoLite2CountryMMDBIn, DescGeoLite2CountryMMDBIn, action, data) }) - lib.RegisterInputConverter(TypeMaxmindMMDBIn, &MMDBIn{ - Description: DescMaxmindMMDBIn, + lib.RegisterInputConverter(TypeGeoLite2CountryMMDBIn, &GeoLite2CountryMMDBIn{ + Description: DescGeoLite2CountryMMDBIn, }) } -type MMDBIn struct { +type GeoLite2CountryMMDBIn struct { Type string Action lib.Action Description string @@ -35,43 +35,43 @@ type MMDBIn struct { OnlyIPType lib.IPType } -func (m *MMDBIn) GetType() string { - return m.Type +func (g *GeoLite2CountryMMDBIn) GetType() string { + return g.Type } -func (m *MMDBIn) GetAction() lib.Action { - return m.Action +func (g *GeoLite2CountryMMDBIn) GetAction() lib.Action { + return g.Action } -func (m *MMDBIn) GetDescription() string { - return m.Description +func (g *GeoLite2CountryMMDBIn) GetDescription() string { + return g.Description } -func (m *MMDBIn) Input(container lib.Container) (lib.Container, error) { +func (g *GeoLite2CountryMMDBIn) Input(container lib.Container) (lib.Container, error) { var content []byte var err error switch { - case strings.HasPrefix(strings.ToLower(m.URI), "http://"), strings.HasPrefix(strings.ToLower(m.URI), "https://"): - content, err = lib.GetRemoteURLContent(m.URI) + case strings.HasPrefix(strings.ToLower(g.URI), "http://"), strings.HasPrefix(strings.ToLower(g.URI), "https://"): + content, err = lib.GetRemoteURLContent(g.URI) default: - content, err = os.ReadFile(m.URI) + content, err = os.ReadFile(g.URI) } if err != nil { return nil, err } entries := make(map[string]*lib.Entry, 300) - err = m.generateEntries(content, entries) + err = g.generateEntries(content, entries) if err != nil { return nil, err } if len(entries) == 0 { - return nil, fmt.Errorf("❌ [type %s | action %s] no entry is generated", m.Type, m.Action) + return nil, fmt.Errorf("❌ [type %s | action %s] no entry is generated", g.Type, g.Action) } var ignoreIPType lib.IgnoreIPOption - switch m.OnlyIPType { + switch g.OnlyIPType { case lib.IPv4: ignoreIPType = lib.IgnoreIPv6 case lib.IPv6: @@ -79,7 +79,7 @@ func (m *MMDBIn) Input(container lib.Container) (lib.Container, error) { } for _, entry := range entries { - switch m.Action { + switch g.Action { case lib.ActionAdd: if err := container.Add(entry, ignoreIPType); err != nil { return nil, err @@ -96,7 +96,7 @@ func (m *MMDBIn) Input(container lib.Container) (lib.Container, error) { return container, nil } -func (m *MMDBIn) generateEntries(content []byte, entries map[string]*lib.Entry) error { +func (g *GeoLite2CountryMMDBIn) generateEntries(content []byte, entries map[string]*lib.Entry) error { db, err := maxminddb.FromBytes(content) if err != nil { return err @@ -109,8 +109,8 @@ func (m *MMDBIn) generateEntries(content []byte, entries map[string]*lib.Entry) var subnet *net.IPNet var err error - switch m.Type { - case TypeMaxmindMMDBIn, TypeDBIPCountryMMDBIn: + switch g.Type { + case TypeGeoLite2CountryMMDBIn, TypeDBIPCountryMMDBIn: var record geoip2.Country subnet, err = networks.Network(&record) if err != nil { @@ -144,7 +144,7 @@ func (m *MMDBIn) generateEntries(content []byte, entries map[string]*lib.Entry) continue } - if len(m.Want) > 0 && !m.Want[name] { + if len(g.Want) > 0 && !g.Want[name] { continue } diff --git a/plugin/maxmind/maxmind_country_mmdb_out.go b/plugin/maxmind/maxmind_country_mmdb_out.go index fbcd9b3f525..cca77632c74 100644 --- a/plugin/maxmind/maxmind_country_mmdb_out.go +++ b/plugin/maxmind/maxmind_country_mmdb_out.go @@ -16,20 +16,20 @@ import ( ) const ( - TypeMaxmindMMDBOut = "maxmindMMDB" - DescMaxmindMMDBOut = "Convert data to MaxMind mmdb database format" + TypeGeoLite2CountryMMDBOut = "maxmindMMDB" + DescGeoLite2CountryMMDBOut = "Convert data to MaxMind mmdb database format" ) func init() { - lib.RegisterOutputConfigCreator(TypeMaxmindMMDBOut, func(action lib.Action, data json.RawMessage) (lib.OutputConverter, error) { - return newMMDBOut(TypeMaxmindMMDBOut, DescMaxmindMMDBOut, action, data) + lib.RegisterOutputConfigCreator(TypeGeoLite2CountryMMDBOut, func(action lib.Action, data json.RawMessage) (lib.OutputConverter, error) { + return newGeoLite2CountryMMDBOut(TypeGeoLite2CountryMMDBOut, DescGeoLite2CountryMMDBOut, action, data) }) - lib.RegisterOutputConverter(TypeMaxmindMMDBOut, &MMDBOut{ - Description: DescMaxmindMMDBOut, + lib.RegisterOutputConverter(TypeGeoLite2CountryMMDBOut, &GeoLite2CountryMMDBOut{ + Description: DescGeoLite2CountryMMDBOut, }) } -type MMDBOut struct { +type GeoLite2CountryMMDBOut struct { Type string Action lib.Action Description string @@ -43,25 +43,25 @@ type MMDBOut struct { SourceMMDBURI string } -func (m *MMDBOut) GetType() string { - return m.Type +func (g *GeoLite2CountryMMDBOut) GetType() string { + return g.Type } -func (m *MMDBOut) GetAction() lib.Action { - return m.Action +func (g *GeoLite2CountryMMDBOut) GetAction() lib.Action { + return g.Action } -func (m *MMDBOut) GetDescription() string { - return m.Description +func (g *GeoLite2CountryMMDBOut) GetDescription() string { + return g.Description } -func (m *MMDBOut) Output(container lib.Container) error { +func (g *GeoLite2CountryMMDBOut) Output(container lib.Container) error { dbName := "" dbDesc := "" recordSize := 28 - switch m.Type { - case TypeMaxmindMMDBOut: + switch g.Type { + case TypeGeoLite2CountryMMDBOut: dbName = "GeoLite2-Country" dbDesc = "Customized GeoLite2 Country database" @@ -88,20 +88,20 @@ func (m *MMDBOut) Output(container lib.Container) error { } // Get extra info - extraInfo, err := m.GetExtraInfo() + extraInfo, err := g.GetExtraInfo() if err != nil { return err } updated := false - for _, name := range m.filterAndSortList(container) { + for _, name := range g.filterAndSortList(container) { entry, found := container.GetEntry(name) if !found { log.Printf("❌ entry %s not found\n", name) continue } - if err := m.marshalData(writer, entry, extraInfo); err != nil { + if err := g.marshalData(writer, entry, extraInfo); err != nil { return err } @@ -109,13 +109,13 @@ func (m *MMDBOut) Output(container lib.Container) error { } if updated { - return m.writeFile(m.OutputName, writer) + return g.writeFile(g.OutputName, writer) } return nil } -func (m *MMDBOut) filterAndSortList(container lib.Container) []string { +func (g *GeoLite2CountryMMDBOut) filterAndSortList(container lib.Container) []string { /* Note: The IPs and/or CIDRs of the latter list will overwrite those of the former one when duplicated data found due to MaxMind mmdb file format constraint. @@ -127,14 +127,14 @@ func (m *MMDBOut) filterAndSortList(container lib.Container) []string { */ excludeMap := make(map[string]bool) - for _, exclude := range m.Exclude { + for _, exclude := range g.Exclude { if exclude = strings.ToUpper(strings.TrimSpace(exclude)); exclude != "" { excludeMap[exclude] = true } } - wantList := make([]string, 0, len(m.Want)) - for _, want := range m.Want { + wantList := make([]string, 0, len(g.Want)) + for _, want := range g.Want { if want = strings.ToUpper(strings.TrimSpace(want)); want != "" && !excludeMap[want] { wantList = append(wantList, want) } @@ -144,9 +144,9 @@ func (m *MMDBOut) filterAndSortList(container lib.Container) []string { return wantList } - overwriteList := make([]string, 0, len(m.Overwrite)) + overwriteList := make([]string, 0, len(g.Overwrite)) overwriteMap := make(map[string]bool) - for _, overwrite := range m.Overwrite { + for _, overwrite := range g.Overwrite { if overwrite = strings.ToUpper(strings.TrimSpace(overwrite)); overwrite != "" && !excludeMap[overwrite] { overwriteList = append(overwriteList, overwrite) overwriteMap[overwrite] = true @@ -171,10 +171,10 @@ func (m *MMDBOut) filterAndSortList(container lib.Container) []string { return list } -func (m *MMDBOut) marshalData(writer *mmdbwriter.Tree, entry *lib.Entry, extraInfo map[string]interface{}) error { +func (g *GeoLite2CountryMMDBOut) marshalData(writer *mmdbwriter.Tree, entry *lib.Entry, extraInfo map[string]any) error { var entryCidr []string var err error - switch m.OnlyIPType { + switch g.OnlyIPType { case lib.IPv4: entryCidr, err = entry.MarshalText(lib.IgnoreIPv6) case lib.IPv6: @@ -187,10 +187,10 @@ func (m *MMDBOut) marshalData(writer *mmdbwriter.Tree, entry *lib.Entry, extraIn } var record mmdbtype.DataType - switch strings.TrimSpace(m.SourceMMDBURI) { + switch strings.TrimSpace(g.SourceMMDBURI) { case "": // No need to get extra info - switch m.Type { - case TypeMaxmindMMDBOut, TypeDBIPCountryMMDBOut: + switch g.Type { + case TypeGeoLite2CountryMMDBOut, TypeDBIPCountryMMDBOut: record = mmdbtype.Map{ "country": mmdbtype.Map{ "iso_code": mmdbtype.String(entry.GetName()), @@ -207,11 +207,11 @@ func (m *MMDBOut) marshalData(writer *mmdbwriter.Tree, entry *lib.Entry, extraIn } default: // Get extra info - switch m.Type { - case TypeMaxmindMMDBOut: + switch g.Type { + case TypeGeoLite2CountryMMDBOut: info, found := extraInfo[entry.GetName()].(geoip2.Country) if !found { - log.Printf("⚠️ [type %s | action %s] not found extra info for list %s\n", m.Type, m.Action, entry.GetName()) + log.Printf("⚠️ [type %s | action %s] not found extra info for list %s\n", g.Type, g.Action, entry.GetName()) record = mmdbtype.Map{ "country": mmdbtype.Map{ @@ -273,7 +273,7 @@ func (m *MMDBOut) marshalData(writer *mmdbwriter.Tree, entry *lib.Entry, extraIn case TypeDBIPCountryMMDBOut: info, found := extraInfo[entry.GetName()].(geoip2.Country) if !found { - log.Printf("⚠️ [type %s | action %s] not found extra info for list %s\n", m.Type, m.Action, entry.GetName()) + log.Printf("⚠️ [type %s | action %s] not found extra info for list %s\n", g.Type, g.Action, entry.GetName()) record = mmdbtype.Map{ "country": mmdbtype.Map{ @@ -347,7 +347,7 @@ func (m *MMDBOut) marshalData(writer *mmdbwriter.Tree, entry *lib.Entry, extraIn }) if !found { - log.Printf("⚠️ [type %s | action %s] not found extra info for list %s\n", m.Type, m.Action, entry.GetName()) + log.Printf("⚠️ [type %s | action %s] not found extra info for list %s\n", g.Type, g.Action, entry.GetName()) record = mmdbtype.Map{ "country": mmdbtype.String(entry.GetName()), @@ -379,12 +379,12 @@ func (m *MMDBOut) marshalData(writer *mmdbwriter.Tree, entry *lib.Entry, extraIn return nil } -func (m *MMDBOut) writeFile(filename string, writer *mmdbwriter.Tree) error { - if err := os.MkdirAll(m.OutputDir, 0755); err != nil { +func (g *GeoLite2CountryMMDBOut) writeFile(filename string, writer *mmdbwriter.Tree) error { + if err := os.MkdirAll(g.OutputDir, 0755); err != nil { return err } - f, err := os.OpenFile(filepath.Join(m.OutputDir, filename), os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644) + f, err := os.OpenFile(filepath.Join(g.OutputDir, filename), os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644) if err != nil { return err } @@ -394,7 +394,7 @@ func (m *MMDBOut) writeFile(filename string, writer *mmdbwriter.Tree) error { return err } - log.Printf("✅ [%s] %s --> %s", m.Type, filename, m.OutputDir) + log.Printf("✅ [%s] %s --> %s", g.Type, filename, g.OutputDir) return nil } diff --git a/plugin/plaintext/clash_in.go b/plugin/plaintext/clash_in.go index 9dc9ae2ddb7..be77cc624af 100644 --- a/plugin/plaintext/clash_in.go +++ b/plugin/plaintext/clash_in.go @@ -13,24 +13,24 @@ which make it possible to support more formats for the project. const ( TypeClashRuleSetClassicalIn = "clashRuleSetClassical" - DescClashClassicalIn = "Convert classical type of Clash RuleSet to other formats (just processing IP & CIDR lines)" + DescClashRuleSetClassicalIn = "Convert classical type of Clash RuleSet to other formats (just processing IP & CIDR lines)" TypeClashRuleSetIPCIDRIn = "clashRuleSet" - DescClashRuleSetIn = "Convert ipcidr type of Clash RuleSet to other formats" + DescClashRuleSetIPCIDRIn = "Convert ipcidr type of Clash RuleSet to other formats" ) func init() { lib.RegisterInputConfigCreator(TypeClashRuleSetClassicalIn, func(action lib.Action, data json.RawMessage) (lib.InputConverter, error) { - return newTextIn(TypeClashRuleSetClassicalIn, DescClashClassicalIn, action, data) + return newTextIn(TypeClashRuleSetClassicalIn, DescClashRuleSetClassicalIn, action, data) }) lib.RegisterInputConverter(TypeClashRuleSetClassicalIn, &TextIn{ - Description: DescClashClassicalIn, + Description: DescClashRuleSetClassicalIn, }) lib.RegisterInputConfigCreator(TypeClashRuleSetIPCIDRIn, func(action lib.Action, data json.RawMessage) (lib.InputConverter, error) { - return newTextIn(TypeClashRuleSetIPCIDRIn, DescClashRuleSetIn, action, data) + return newTextIn(TypeClashRuleSetIPCIDRIn, DescClashRuleSetIPCIDRIn, action, data) }) lib.RegisterInputConverter(TypeClashRuleSetIPCIDRIn, &TextIn{ - Description: DescClashRuleSetIn, + Description: DescClashRuleSetIPCIDRIn, }) } diff --git a/plugin/plaintext/clash_out.go b/plugin/plaintext/clash_out.go index 596a53842b8..e7a97f1b21f 100644 --- a/plugin/plaintext/clash_out.go +++ b/plugin/plaintext/clash_out.go @@ -13,24 +13,24 @@ which make it possible to support more formats for the project. const ( TypeClashRuleSetClassicalOut = "clashRuleSetClassical" - DescClashClassicalOut = "Convert data to classical type of Clash RuleSet" + DescClashRuleSetClassicalOut = "Convert data to classical type of Clash RuleSet" TypeClashRuleSetIPCIDROut = "clashRuleSet" - DescClashRuleSetOut = "Convert data to ipcidr type of Clash RuleSet" + DescClashRuleSetIPCIDROut = "Convert data to ipcidr type of Clash RuleSet" ) func init() { lib.RegisterOutputConfigCreator(TypeClashRuleSetClassicalOut, func(action lib.Action, data json.RawMessage) (lib.OutputConverter, error) { - return newTextOut(TypeClashRuleSetClassicalOut, DescClashClassicalOut, action, data) + return newTextOut(TypeClashRuleSetClassicalOut, DescClashRuleSetClassicalOut, action, data) }) lib.RegisterOutputConverter(TypeClashRuleSetClassicalOut, &TextOut{ - Description: DescClashClassicalOut, + Description: DescClashRuleSetClassicalOut, }) lib.RegisterOutputConfigCreator(TypeClashRuleSetIPCIDROut, func(action lib.Action, data json.RawMessage) (lib.OutputConverter, error) { - return newTextOut(TypeClashRuleSetIPCIDROut, DescClashRuleSetOut, action, data) + return newTextOut(TypeClashRuleSetIPCIDROut, DescClashRuleSetIPCIDROut, action, data) }) lib.RegisterOutputConverter(TypeClashRuleSetIPCIDROut, &TextOut{ - Description: DescClashRuleSetOut, + Description: DescClashRuleSetIPCIDROut, }) } diff --git a/plugin/v2ray/dat_in.go b/plugin/v2ray/dat_in.go index af30660048c..0c5cb6a0a33 100644 --- a/plugin/v2ray/dat_in.go +++ b/plugin/v2ray/dat_in.go @@ -14,16 +14,16 @@ import ( ) const ( - TypeGeoIPdatIn = "v2rayGeoIPDat" - DescGeoIPdatIn = "Convert V2Ray GeoIP dat to other formats" + TypeGeoIPDatIn = "v2rayGeoIPDat" + DescGeoIPDatIn = "Convert V2Ray GeoIP dat to other formats" ) func init() { - lib.RegisterInputConfigCreator(TypeGeoIPdatIn, func(action lib.Action, data json.RawMessage) (lib.InputConverter, error) { + lib.RegisterInputConfigCreator(TypeGeoIPDatIn, func(action lib.Action, data json.RawMessage) (lib.InputConverter, error) { return newGeoIPDatIn(action, data) }) - lib.RegisterInputConverter(TypeGeoIPdatIn, &GeoIPDatIn{ - Description: DescGeoIPdatIn, + lib.RegisterInputConverter(TypeGeoIPDatIn, &GeoIPDatIn{ + Description: DescGeoIPDatIn, }) } @@ -41,7 +41,7 @@ func newGeoIPDatIn(action lib.Action, data json.RawMessage) (lib.InputConverter, } if tmp.URI == "" { - return nil, fmt.Errorf("❌ [type %s | action %s] uri must be specified in config", TypeGeoIPdatIn, action) + return nil, fmt.Errorf("❌ [type %s | action %s] uri must be specified in config", TypeGeoIPDatIn, action) } // Filter want list @@ -53,9 +53,9 @@ func newGeoIPDatIn(action lib.Action, data json.RawMessage) (lib.InputConverter, } return &GeoIPDatIn{ - Type: TypeGeoIPdatIn, + Type: TypeGeoIPDatIn, Action: action, - Description: DescGeoIPdatIn, + Description: DescGeoIPDatIn, URI: tmp.URI, Want: wantList, OnlyIPType: tmp.OnlyIPType, diff --git a/plugin/v2ray/dat_out.go b/plugin/v2ray/dat_out.go index 3e1cdbda8a7..910629701e7 100644 --- a/plugin/v2ray/dat_out.go +++ b/plugin/v2ray/dat_out.go @@ -16,8 +16,8 @@ import ( ) const ( - TypeGeoIPdatOut = "v2rayGeoIPDat" - DescGeoIPdatOut = "Convert data to V2Ray GeoIP dat format" + TypeGeoIPDatOut = "v2rayGeoIPDat" + DescGeoIPDatOut = "Convert data to V2Ray GeoIP dat format" ) var ( @@ -26,15 +26,15 @@ var ( ) func init() { - lib.RegisterOutputConfigCreator(TypeGeoIPdatOut, func(action lib.Action, data json.RawMessage) (lib.OutputConverter, error) { - return newGeoIPDat(action, data) + lib.RegisterOutputConfigCreator(TypeGeoIPDatOut, func(action lib.Action, data json.RawMessage) (lib.OutputConverter, error) { + return newGeoIPDatOut(action, data) }) - lib.RegisterOutputConverter(TypeGeoIPdatOut, &GeoIPDatOut{ - Description: DescGeoIPdatOut, + lib.RegisterOutputConverter(TypeGeoIPDatOut, &GeoIPDatOut{ + Description: DescGeoIPDatOut, }) } -func newGeoIPDat(action lib.Action, data json.RawMessage) (lib.OutputConverter, error) { +func newGeoIPDatOut(action lib.Action, data json.RawMessage) (lib.OutputConverter, error) { var tmp struct { OutputName string `json:"outputName"` OutputDir string `json:"outputDir"` @@ -59,9 +59,9 @@ func newGeoIPDat(action lib.Action, data json.RawMessage) (lib.OutputConverter, } return &GeoIPDatOut{ - Type: TypeGeoIPdatOut, + Type: TypeGeoIPDatOut, Action: action, - Description: DescGeoIPdatOut, + Description: DescGeoIPDatOut, OutputName: tmp.OutputName, OutputDir: tmp.OutputDir, Want: tmp.Want,