# Using IPinfo's MMDB data downloads with Golang

**URL:** <https://community.ipinfo.io/t/using-ipinfos-mmdb-data-downloads-with-golang/4415>\
**Category:** Database Downloads\
**Tags:** golang, go\
**Created:** [December 12, 2023, 1:36pm UTC](https://community.ipinfo.io/t/using-ipinfos-mmdb-data-downloads-with-golang/4415 "2023-12-12T13:36:47Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![Abdullah](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.ipinfo.io/abdullah/32/4973_2.png) [@Abdullah](https://community.ipinfo.io/u/Abdullah)\
**Post date:** [December 12, 2023, 1:36pm UTC](https://community.ipinfo.io/t/using-ipinfos-mmdb-data-downloads-with-golang/4415/1 "2023-12-12T13:36:47Z")

</div>

# Using IPinfo’s MMDB data downloads with Golang

The `.mmdb` file format is a special binary database type requiring specific packages/libraries to read. The `.mmdb` file format facilitates extremely fast IP lookup operations.

I highly recommend reading this article before getting started: [How to choose the best file format for your IPinfo database? - IPinfo.io](https://ipinfo.io/blog/ipinfo-database-formats/)

### 0. Prerequisite: Downloading the IPinfo IP database in the `.mmdb` format

Before you begin, download the `.mmdb` format data. Keep this database in our same directory.

For this example, I use the [IPinfo IP to Privacy Detection Database](https://ipinfo.io/products/anonymous-ip-database). [IPinfo IP to Privacy Detection Database](https://ipinfo.io/products/anonymous-ip-database) is stored as `standard_privacy.mmdb`.

🔗 The database schema for the [IPinfo IP to Privacy Detection Database](https://ipinfo.io/products/anonymous-ip-database): [Documentation for IP Privacy Detection Database - IPinfo.io](https://ipinfo.io/developers/privacy-detection-database)

> **[Documentation for IP Privacy Detection Database](https://ipinfo.io/developers/privacy-detection-database)**
>
> We're the trusted source for IP address information, handling 50 billion IP geolocation API requests per month for over 1,000 businesses and 100,000+ developers

### 1. Installation of `maxminddb-golang`

After running `go mod init`, you must install the `maxminddb-golang`. This library will perform the IP lookup operations.

> Please note that the required package is an MMDB reader, not an API package.

To install the package, run the following command:

```bash
go get github.com/oschwald/maxminddb-golang

```

You can find the documentation for the package here: [maxminddb package - github.com/oschwald/maxminddb-golang - Go Packages](https://pkg.go.dev/github.com/oschwald/maxminddb-golang)

> **[maxminddb package - github.com/oschwald/maxminddb-golang - Go Packages](https://pkg.go.dev/github.com/oschwald/maxminddb-golang)**
>
> Package maxminddb provides a reader for the MaxMind DB file format.

### 2. Usage

After the installation of the `maxminddb-golang` package, you can use the following code to lookup the IPinfo results from the MMDB file.

```go
package main

import (
	"fmt"
	"log"
	"net"

	"github.com/oschwald/maxminddb-golang"
)

// Refer to the IPinfo database documentation to create the struct: https://ipinfo.io/developers/database-types
type IPinfoResult struct {
	Hosting string `maxminddb:"hosting"`
	Proxy string `maxminddb:"proxy"`
	Tor string `maxminddb:"tor"`
	Vpn string `maxminddb:"vpn"`
	Relay string `maxminddb:"relay"`
	Service string `maxminddb:"service"`
}

func main() {
	// Replace the following with the path to your IPinfo IP database.
	// My IP to Privacy Detection database is available in the same directory
	dbPath := "./standard_privacy.mmdb"

	// Open the MaxMind DB file
	db, err := maxminddb.Open(dbPath)
	if err != nil {
		log.Fatal(err)
	}
	defer db.Close()

	// Provide an IP address that you want to lookup
	// For example, I am looking up the random IP address
	ip := net.ParseIP("188.241.83.0")

	// Create a struct to store the result
	var result IPinfoResult

	// Lookup the IP address in the MaxMind DB
	err = db.Lookup(ip, &result)
	if err != nil {
		log.Fatal(err)
	}

	// Print the entire result payload
	fmt.Printf("%+v\n", result)

	// Print the individual result payload
	fmt.Printf("Hosting: %s\n", result.Hosting)
	fmt.Printf("Proxy: %s\n", result.Proxy)
	fmt.Printf("Tor: %s\n", result.Tor)
	fmt.Printf("VPN: %s\n", result.Vpn)
	fmt.Printf("Relay: %s\n", result.Relay)
	fmt.Printf("Anonymous IP Service Name: %s\n", result.Service)

}

```

Output:

```auto
{Hosting:true Proxy: Tor: Vpn:true Relay: Service:Windscribe}
Hosting: true
Proxy: 
Tor: 
VPN: true
Relay: 
Anonymous IP Service Name: Windscribe

```

### Some points to note:

- If the IP address is not available, for instance, if you look for a non-anonymous IP address in the IP to Privacy database, you will get empty results similar to this:

```auto
{Hosting: Proxy: Tor: Vpn: Relay: Service:}
Hosting: 
Proxy: 
Tor: 
VPN: 
Relay: 
Anonymous IP Service Name: 

```

- You might need to convert the string boolean values in the database to `bool` types.

- To create the `IPinfoResult` struct, you should refer to our database schema documentation: [Documentation for IP Database Types - IPinfo.io](https://ipinfo.io/developers/database-types)

---

_[View the full topic](https://community.ipinfo.io/t/using-ipinfos-mmdb-data-downloads-with-golang/4415)._
