summaryrefslogtreecommitdiff
path: root/plugin/maxmind/common_out.go
diff options
context:
space:
mode:
authorLoyalsoldier <[email protected]>2025-02-01 15:13:39 +0800
committerLoyalsoldier <[email protected]>2025-02-01 15:27:23 +0800
commitfdab3dd2dea595f4aecd48bfd725b4bacf315b62 (patch)
tree8d2d772a9415b74a7caa68ce5bc6a08f34fdf6b7 /plugin/maxmind/common_out.go
parentd9ccff71c634dae0ed85608d37b2d0c2d732fa1a (diff)
Diffstat (limited to 'plugin/maxmind/common_out.go')
-rw-r--r--plugin/maxmind/common_out.go29
1 files changed, 15 insertions, 14 deletions
diff --git a/plugin/maxmind/common_out.go b/plugin/maxmind/common_out.go
index ad5edce6..bfd41aaa 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