Files
whitepaper_obsero/probe/pkg/geo/geo.go
T
2025-04-29 23:31:22 +02:00

25 lines
495 B
Go

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
}