2022-06-09 23:47:12 +00:00
|
|
|
package updater
|
2021-05-09 00:51:34 +00:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
2023-05-20 19:58:18 +00:00
|
|
|
"net/netip"
|
2021-05-09 00:51:34 +00:00
|
|
|
|
|
|
|
|
"github.com/qdm12/gluetun/internal/models"
|
2022-06-12 00:09:01 +00:00
|
|
|
"github.com/qdm12/gluetun/internal/provider/common"
|
2024-02-13 11:11:10 +00:00
|
|
|
"github.com/qdm12/gluetun/internal/publicip/api"
|
2021-05-09 00:51:34 +00:00
|
|
|
)
|
|
|
|
|
|
2022-06-12 00:09:01 +00:00
|
|
|
func setLocationInfo(ctx context.Context, fetcher common.IPFetcher, servers []models.Server) (err error) {
|
2021-05-09 00:51:34 +00:00
|
|
|
// Get public IP address information
|
2023-05-20 19:58:18 +00:00
|
|
|
ipsToGetInfo := make([]netip.Addr, 0, len(servers))
|
2022-04-16 21:58:42 +02:00
|
|
|
for _, server := range servers {
|
|
|
|
|
ipsToGetInfo = append(ipsToGetInfo, server.IPs...)
|
2021-05-09 00:51:34 +00:00
|
|
|
}
|
2024-02-13 11:11:10 +00:00
|
|
|
ipsInfo, err := api.FetchMultiInfo(ctx, fetcher, ipsToGetInfo)
|
2021-05-09 00:51:34 +00:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for i := range servers {
|
|
|
|
|
ipInfo := ipsInfo[i]
|
|
|
|
|
servers[i].Country = ipInfo.Country
|
|
|
|
|
servers[i].Region = ipInfo.Region
|
|
|
|
|
servers[i].City = ipInfo.City
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|