Skip to content

Commit

Permalink
Chore: refine reading MMDB file
Browse files Browse the repository at this point in the history
  • Loading branch information
Loyalsoldier committed Nov 5, 2024
1 parent 9b3bc0b commit c9a7b29
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 13 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.23
toolchain go1.23.2

require (
github.com/oschwald/geoip2-golang v1.11.0
github.com/oschwald/maxminddb-golang v1.13.1
github.com/tailscale/hujson v0.0.0-20241010212012-29efb4a0184b
go4.org/netipx v0.0.0-20231129151722-fdeea329fbba
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/oschwald/geoip2-golang v1.11.0 h1:hNENhCn1Uyzhf9PTmquXENiWS6AlxAEnBII6r8krA3w=
github.com/oschwald/geoip2-golang v1.11.0/go.mod h1:P9zG+54KPEFOliZ29i7SeYZ/GM6tfEL+rgSn03hYuUo=
github.com/oschwald/maxminddb-golang v1.13.1 h1:G3wwjdN9JmIK2o/ermkHM+98oX5fS+k5MbwsmL4MRQE=
github.com/oschwald/maxminddb-golang v1.13.1/go.mod h1:K4pgV9N/GcK694KSTmVSDTODk4IsCNThNdTmnaBZ/F8=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down
16 changes: 3 additions & 13 deletions plugin/maxmind/mmdb_in.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"path/filepath"
"strings"

"github.com/oschwald/geoip2-golang"
"github.com/oschwald/maxminddb-golang"
"github.com/v2fly/geoip/lib"
)
Expand Down Expand Up @@ -143,21 +144,10 @@ func (m *maxmindMMDBIn) generateEntries(content []byte, entries map[string]*lib.

networks := db.Networks(maxminddb.SkipAliasedNetworks)
for networks.Next() {
record := struct {
Country struct {
IsoCode string `maxminddb:"iso_code"`
} `maxminddb:"country"`
RegisteredCountry struct {
IsoCode string `maxminddb:"iso_code"`
} `maxminddb:"registered_country"`
RepresentedCountry struct {
IsoCode string `maxminddb:"iso_code"`
} `maxminddb:"represented_country"`
}{}

var record geoip2.Country
subnet, err := networks.Network(&record)
if err != nil {
continue
return err
}

name := ""
Expand Down

0 comments on commit c9a7b29

Please sign in to comment.