add probe folder
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
package geo
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type GeoInfo struct {
|
||||
Country string `json:"country"`
|
||||
Region string `json:"regionName"`
|
||||
City string `json:"city"`
|
||||
}
|
||||
|
||||
func GetGeoLocation() GeoInfo {
|
||||
resp, err := http.Get("http://ip-api.com/json")
|
||||
if err != nil {
|
||||
return GeoInfo{Country: "Unknown", Region: "Unknown", City: "Unknown"}
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
var info GeoInfo
|
||||
json.NewDecoder(resp.Body).Decode(&info)
|
||||
return info
|
||||
}
|
||||
Reference in New Issue
Block a user