From 4ae43584f3a6f586a1c2ee05e87b885822cc2afa Mon Sep 17 00:00:00 2001 From: Gregory Oschwald Date: Sun, 2 Jun 2024 19:16:14 -0700 Subject: [PATCH 1/2] Add is_anycast output for location DBs --- reader.go | 3 +++ reader_test.go | 15 +++++++++++++++ test-data | 2 +- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/reader.go b/reader.go index 70980b2..7e9e0a6 100644 --- a/reader.go +++ b/reader.go @@ -70,6 +70,7 @@ type Enterprise struct { AutonomousSystemNumber uint `maxminddb:"autonomous_system_number"` StaticIPScore float64 `maxminddb:"static_ip_score"` IsAnonymousProxy bool `maxminddb:"is_anonymous_proxy"` + IsAnycast bool `maxminddb:"is_anycast"` IsLegitimateProxy bool `maxminddb:"is_legitimate_proxy"` IsSatelliteProvider bool `maxminddb:"is_satellite_provider"` } `maxminddb:"traits"` @@ -130,6 +131,7 @@ type City struct { } `maxminddb:"location"` Traits struct { IsAnonymousProxy bool `maxminddb:"is_anonymous_proxy"` + IsAnycast bool `maxminddb:"is_anycast"` IsSatelliteProvider bool `maxminddb:"is_satellite_provider"` } `maxminddb:"traits"` } @@ -163,6 +165,7 @@ type Country struct { } `maxminddb:"represented_country"` Traits struct { IsAnonymousProxy bool `maxminddb:"is_anonymous_proxy"` + IsAnycast bool `maxminddb:"is_anycast"` IsSatelliteProvider bool `maxminddb:"is_satellite_provider"` } `maxminddb:"traits"` } diff --git a/reader_test.go b/reader_test.go index 606203b..56e0552 100644 --- a/reader_test.go +++ b/reader_test.go @@ -118,6 +118,21 @@ func TestReader(t *testing.T) { assert.False(t, record.RepresentedCountry.IsInEuropeanUnion) } +func TestIsAnycast(t *testing.T) { + for _, test := range []string{"Country", "City", "Enterprise"} { + t.Run(test, func(t *testing.T) { + reader, err := Open("test-data/test-data/GeoIP2-" + test + "-Test.mmdb") + require.NoError(t, err) + defer reader.Close() + + record, err := reader.City(net.ParseIP("214.1.1.0")) + require.NoError(t, err) + + assert.True(t, record.Traits.IsAnycast) + }) + } +} + func TestMetroCode(t *testing.T) { reader, err := Open("test-data/test-data/GeoIP2-City-Test.mmdb") require.NoError(t, err) diff --git a/test-data b/test-data index 3e225a8..0a9c1aa 160000 --- a/test-data +++ b/test-data @@ -1 +1 @@ -Subproject commit 3e225a82e492a58eef738ef2b6e94aa4f50ef932 +Subproject commit 0a9c1aa26cd7b91bee2efe27e7d174797d8211a6 From 3d75acaa8602b900bad46fff8f66f19d5b95e918 Mon Sep 17 00:00:00 2001 From: Gregory Oschwald Date: Sun, 2 Jun 2024 19:17:10 -0700 Subject: [PATCH 2/2] Update maxminddb --- go.mod | 2 +- go.sum | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 59859eb..b45cb1b 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/oschwald/geoip2-golang go 1.21 require ( - github.com/oschwald/maxminddb-golang v1.12.0 + github.com/oschwald/maxminddb-golang v1.13.0 github.com/stretchr/testify v1.9.0 ) diff --git a/go.sum b/go.sum index 4739512..bf09fa4 100644 --- a/go.sum +++ b/go.sum @@ -1,13 +1,11 @@ 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/oschwald/maxminddb-golang v1.12.0 h1:9FnTOD0YOhP7DGxGsq4glzpGy5+w7pq50AS6wALUMYs= -github.com/oschwald/maxminddb-golang v1.12.0/go.mod h1:q0Nob5lTCqyQ8WT6FYgS1L7PXKVVbgiymefNwIjPzgY= +github.com/oschwald/maxminddb-golang v1.13.0 h1:R8xBorY71s84yO06NgTmQvqvTvlS/bnYZrrWX1MElnU= +github.com/oschwald/maxminddb-golang v1.13.0/go.mod h1:BU0z8BfFVhi1LQaonTwwGQlsHUEu9pWNdMfmq4ztm0o= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA= -golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=