github.com/jimpick/sp-kyc-checks@v0.0.0-20230201194251-fa84fca72da8/checks/geoip/geolite2.go (about) 1 package geoip 2 3 import ( 4 "encoding/json" 5 "os" 6 ) 7 8 type IPsGeolite2Report struct { 9 Date *string `json:"date"` 10 IPs map[string]IPsGeolite2Record `json:"ipsGeolite2"` 11 } 12 13 type IPsGeolite2Record struct { 14 Epoch uint64 `json:"epoch"` 15 Timestamp string `json:"timestamp"` 16 Continent string `json:"continent"` 17 Country string `json:"country"` 18 Subdiv1 string `json:"subdiv1"` 19 City string `json:"city"` 20 Long float32 `json:"long"` 21 Lat float32 `json:"lat"` 22 Geolite2 Geolite2Detail 23 } 24 25 type Geolite2Detail map[string]interface{} 26 27 func LoadIPsGeolite2() (map[string]IPsGeolite2Record, error) { 28 file := os.Getenv("IPS_GEOLITE2") 29 if file == "" { 30 file = "testdata/ips-geolite2-latest.json" 31 } 32 bytes, err := os.ReadFile(file) 33 if err != nil { 34 return nil, err 35 } 36 var report IPsGeolite2Report 37 json.Unmarshal(bytes, &report) 38 return report.IPs, nil 39 }