From 53ee156e6701ea23b59b20bd819e97804715993f Mon Sep 17 00:00:00 2001 From: LandaMm Date: Wed, 11 Jun 2025 18:48:54 +0200 Subject: [PATCH] feat: get location util --- internal/util/location.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 internal/util/location.go 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 +}