feat: get location util

This commit is contained in:
2025-06-11 18:48:54 +02:00
parent 07a936acc7
commit 53ee156e67

24
internal/util/location.go Normal file
View File

@ -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
}