PageRenderTime 4ms CodeModel.GetById 1ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/api/ip_database.go

https://gitlab.com/voxxit/gogeoip2
Go | 31 lines | 23 code | 8 blank | 0 comment | 4 complexity | cebb1ecbdf19ae77a802e879a825854c MD5 | raw file
 1package api
 2
 3import (
 4	"log"
 5
 6	"github.com/oschwald/geoip2-golang"
 7)
 8
 9type IPDatabase struct {
10	Isp  *geoip2.Reader
11	City *geoip2.Reader
12}
13
14func OpenDatabases() *IPDatabase {
15	db := &IPDatabase{}
16
17	isp, err := geoip2.Open("GeoIP2-ISP.mmdb")
18	if err != nil {
19		log.Fatal(err)
20	}
21
22	city, err := geoip2.Open("GeoLite2-City.mmdb")
23	if err != nil {
24		log.Fatal(err)
25	}
26
27	db.Isp = isp
28	db.City = city
29
30	return db
31}