Skip to content

Commit

Permalink
Chore: make names consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
Loyalsoldier committed Feb 1, 2025
1 parent d9ccff7 commit fdab3dd
Show file tree
Hide file tree
Showing 15 changed files with 178 additions and 177 deletions.
22 changes: 11 additions & 11 deletions lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,24 +162,24 @@ 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,
URI: uri,
}

case strings.ToLower(maxmind.TypeIPInfoCountryMMDBIn):
input = &maxmind.MMDBIn{
input = &maxmind.GeoLite2CountryMMDBIn{
Type: maxmind.TypeIPInfoCountryMMDBIn,
Action: lib.ActionAdd,
Description: maxmind.DescIPInfoCountryMMDBIn,
Expand All @@ -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,
}

Expand All @@ -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,
Expand All @@ -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,
Expand Down
14 changes: 7 additions & 7 deletions plugin/maxmind/common_in.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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
Expand All @@ -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,
Expand Down
29 changes: 15 additions & 14 deletions plugin/maxmind/common_out.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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:
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions plugin/maxmind/dbip_country_mmdb_in.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
}
4 changes: 2 additions & 2 deletions plugin/maxmind/dbip_country_mmdb_out.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
}
4 changes: 2 additions & 2 deletions plugin/maxmind/ipinfo_country_mmdb_in.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
}
4 changes: 2 additions & 2 deletions plugin/maxmind/ipinfo_country_mmdb_out.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
}
40 changes: 20 additions & 20 deletions plugin/maxmind/maxmind_asn_csv_in.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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
Expand Down Expand Up @@ -85,18 +85,18 @@ 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,
OnlyIPType: tmp.OnlyIPType,
}, nil
}

type GeoLite2ASNCSV struct {
type GeoLite2ASNCSVIn struct {
Type string
Action lib.Action
Description string
Expand All @@ -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 != "" {
Expand Down Expand Up @@ -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)
}
Expand Down
Loading

0 comments on commit fdab3dd

Please sign in to comment.