diff --git a/internal/util/location.go b/internal/util/location.go new file mode 100644 index 0000000..297e271 --- /dev/null +++ b/internal/util/location.go @@ -0,0 +1,24 @@ +package util + +import ( + "encoding/json" + "net/http" +) + +type LocationResult struct { + Country string `json:"country"` + Region string `json:"regionName"` + City string `json:"city"` +} + +func GetLocation(ip string) (LocationResult, error) { + var loc LocationResult + // Example using ipinfo.io free API + resp, err := http.Get("https://ipinfo.io/" + ip + "/json") + if err != nil { + return loc, err + } + defer resp.Body.Close() + json.NewDecoder(resp.Body).Decode(&loc) + return loc, nil +}