| 1 | package workbench |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "net" |
| 6 | "net/http" |
| 7 | |
| 8 | "github.com/sylvinus/agent-vm/internal/exitpolicy" |
| 9 | ) |
| 10 | |
| 11 | func lookupLocation(ctx context.Context, client *http.Client, address net.IP) (Location, error) { |
| 12 | loc, err := exitpolicy.Lookup(ctx, client, address) |
| 13 | if err != nil { |
| 14 | return Location{}, err |
| 15 | } |
| 16 | locale, browser := languageSuggestion(loc.CountryCode) |
| 17 | return Location{ |
| 18 | IP: loc.IP, Country: loc.Country, CountryCode: loc.CountryCode, |
| 19 | Region: loc.Region, RegionCode: loc.RegionCode, City: loc.City, |
| 20 | Timezone: loc.Timezone, CheckedAt: loc.CheckedAt, |
| 21 | SuggestedLocale: locale, SuggestedBrowserLanguage: browser, |
| 22 | }, nil |
| 23 | } |