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