New file |
| | |
| | | ```cassandraql |
| | | package main |
| | | |
| | | import ( |
| | | "fmt" |
| | | "basic.com/valib/iploc.git" |
| | | ) |
| | | |
| | | func main() { |
| | | geo, err := iploc.GetLocation() |
| | | if err == nil { |
| | | fmt.Println(geo) |
| | | } else { |
| | | fmt.Println("GetLocation:", err) |
| | | } |
| | | |
| | | geo, err = iploc.GetLocationForIp("114.114.114.114") |
| | | if err == nil { |
| | | fmt.Println(geo) |
| | | } else { |
| | | fmt.Println("GetLocationForIp:", err) |
| | | } |
| | | } |
| | | ``` |
| | |
| | | |
| | | // Data from ip-api.com |
| | | type GeoIP struct { |
| | | InternetIp string `json:"query"` |
| | | Country string `json:"country"` |
| | | RegionName string `json:"regionName"` |
| | | City string `json:"city"` |
| | | InternetIp string `json:"query"` // 外网ip |
| | | Country string `json:"country"` // 国家 |
| | | RegionName string `json:"regionName"` // 地区 |
| | | City string `json:"city"` // 城市 |
| | | Lat float64 `json:"lat"` |
| | | Lon float64 `json:"lon"` |
| | | } |
| | |
| | | fmt.Println("GetLocation:", err) |
| | | } |
| | | |
| | | geo, _ = GetLocationForIp("114.114.114.114") |
| | | geo, err = GetLocationForIp("114.114.114.114") |
| | | if err == nil { |
| | | fmt.Println(geo) |
| | | } else { |