@@ -11,7 +11,7 @@ This library is built using
1111data for the database record is decoded using this library. Version 2.0
1212provides significant performance improvements with 56% fewer allocations and
131334% less memory usage compared to v1. Version 2.0 also adds ` Network ` and
14- ` IPAddress ` fields to all result structs, and includes an ` IsZero ()` method to
14+ ` IPAddress ` fields to all result structs, and includes a ` HasData ()` method to
1515easily check if data was found. If you only need several fields, you may get
1616superior performance by using maxminddb's ` Lookup ` directly with a result
1717struct that only contains the required fields. (See
@@ -32,7 +32,7 @@ Version 2.0 includes several major improvements:
3232- ** Modern API** : Uses ` netip.Addr ` instead of ` net.IP ` for better performance
3333- ** Network Information** : All result structs now include ` Network ` and
3434 ` IPAddress ` fields
35- - ** Data Validation** : New ` IsZero ()` method to easily check if data was found
35+ - ** Data Validation** : New ` HasData ()` method to easily check if data was found
3636- ** Structured Names** : Replaced ` map[string]string ` with typed ` Names ` struct
3737 for better performance
3838- ** Go 1.24 Support** : Uses ` omitzero ` JSON tags to match MaxMind database
@@ -71,7 +71,7 @@ func main() {
7171 if err != nil {
7272 log.Fatal (err)
7373 }
74- if record.IsZero () {
74+ if ! record.HasData () {
7575 fmt.Println (" No data found for this IP" )
7676 return
7777 }
@@ -82,7 +82,9 @@ func main() {
8282 fmt.Printf (" Russian country name: %v \n " , record.Country .Names .Russian )
8383 fmt.Printf (" ISO country code: %v \n " , record.Country .ISOCode )
8484 fmt.Printf (" Time zone: %v \n " , record.Location .TimeZone )
85- fmt.Printf (" Coordinates: %v , %v \n " , record.Location .Latitude , record.Location .Longitude )
85+ if record.Location .HasCoordinates () {
86+ fmt.Printf (" Coordinates: %v , %v \n " , *record.Location .Latitude , *record.Location .Longitude )
87+ }
8688 // Output:
8789 // Portuguese (BR) city name: Londres
8890 // English subdivision name: England
@@ -151,7 +153,7 @@ func main() {
151153 log.Fatal (err)
152154 }
153155
154- if record.IsZero () {
156+ if ! record.HasData () {
155157 fmt.Println (" No data found for this IP" )
156158 return
157159 }
@@ -161,7 +163,9 @@ func main() {
161163 fmt.Printf (" Country: %v (%v )\n " , record.Country .Names .English , record.Country .ISOCode )
162164 fmt.Printf (" Continent: %v (%v )\n " , record.Continent .Names .English , record.Continent .Code )
163165 fmt.Printf (" Postal Code: %v \n " , record.Postal .Code )
164- fmt.Printf (" Location: %v , %v \n " , record.Location .Latitude , record.Location .Longitude )
166+ if record.Location .HasCoordinates () {
167+ fmt.Printf (" Location: %v , %v \n " , *record.Location .Latitude , *record.Location .Longitude )
168+ }
165169 fmt.Printf (" Time Zone: %v \n " , record.Location .TimeZone )
166170 fmt.Printf (" Network: %v \n " , record.Traits .Network )
167171 fmt.Printf (" IP Address: %v \n " , record.Traits .IPAddress )
@@ -200,7 +204,7 @@ func main() {
200204 log.Fatal (err)
201205 }
202206
203- if record.IsZero () {
207+ if ! record.HasData () {
204208 fmt.Println (" No data found for this IP" )
205209 return
206210 }
@@ -251,7 +255,7 @@ func main() {
251255 log.Fatal (err)
252256 }
253257
254- if record.IsZero () {
258+ if ! record.HasData () {
255259 fmt.Println (" No data found for this IP" )
256260 return
257261 }
@@ -296,7 +300,7 @@ func main() {
296300 log.Fatal (err)
297301 }
298302
299- if record.IsZero () {
303+ if ! record.HasData () {
300304 fmt.Println (" No data found for this IP" )
301305 return
302306 }
@@ -345,15 +349,17 @@ func main() {
345349 log.Fatal (err)
346350 }
347351
348- if record.IsZero () {
352+ if ! record.HasData () {
349353 fmt.Println (" No data found for this IP" )
350354 return
351355 }
352356
353357 // Basic location information
354358 fmt.Printf (" City: %v \n " , record.City .Names .English )
355359 fmt.Printf (" Country: %v (%v )\n " , record.Country .Names .English , record.Country .ISOCode )
356- fmt.Printf (" Location: %v , %v \n " , record.Location .Latitude , record.Location .Longitude )
360+ if record.Location .HasCoordinates () {
361+ fmt.Printf (" Location: %v , %v \n " , *record.Location .Latitude , *record.Location .Longitude )
362+ }
357363
358364 // Enterprise-specific fields
359365 fmt.Printf (" ISP: %v \n " , record.Traits .ISP )
@@ -410,7 +416,7 @@ func main() {
410416 log.Fatal (err)
411417 }
412418
413- if record.IsZero () {
419+ if ! record.HasData () {
414420 fmt.Println (" No data found for this IP" )
415421 return
416422 }
@@ -464,7 +470,7 @@ func main() {
464470 log.Fatal (err)
465471 }
466472
467- if record.IsZero () {
473+ if ! record.HasData () {
468474 fmt.Println (" No data found for this IP" )
469475 return
470476 }
@@ -507,7 +513,7 @@ func main() {
507513 log.Fatal (err)
508514 }
509515
510- if record.IsZero () {
516+ if ! record.HasData () {
511517 fmt.Println (" No data found for this IP" )
512518 return
513519 }
@@ -551,7 +557,7 @@ func main() {
551557 }
552558
553559 // Always check if data was found
554- if record.IsZero () {
560+ if ! record.HasData () {
555561 fmt.Println (" No data found for this IP address" )
556562 return
557563 }
@@ -627,7 +633,7 @@ fmt.Println(string(jsonData))
627633- ** IP Type** : Use ` netip.Addr ` instead of ` net.IP `
628634- ** Field Names** : ` IsoCode ` → ` ISOCode `
629635- ** Names Access** : Use struct fields instead of map access
630- - ** Data Validation** : Use ` IsZero ()` method to check for data availability
636+ - ** Data Validation** : Use ` HasData ()` method to check for data availability
631637
632638### Migration Example
633639
@@ -647,7 +653,7 @@ if err != nil {
647653 // handle error
648654}
649655record , err := db.City (ip)
650- if record.IsZero () {
656+ if ! record.HasData () {
651657 // handle no data found
652658}
653659cityName := record.City .Names .English
@@ -659,7 +665,7 @@ cityName := record.City.Names.English
659665
660666** Database not found** : Ensure the .mmdb file path is correct and readable.
661667
662- ** No data returned** : Check if ` IsZero ()` returns true - the IP may not be in
668+ ** No data returned** : Check if ` HasData ()` returns false - the IP may not be in
663669the database or may be a private/reserved IP.
664670
665671** Performance issues** : Ensure you're reusing the database instance rather than
0 commit comments