2021-05-09 00:51:34 +00:00
|
|
|
package privado
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"net"
|
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
|
|
"github.com/qdm12/gluetun/internal/models"
|
|
|
|
|
"github.com/qdm12/gluetun/internal/publicip"
|
|
|
|
|
)
|
|
|
|
|
|
2022-04-16 22:25:36 +02:00
|
|
|
func setLocationInfo(ctx context.Context, client *http.Client, servers []models.Server) (err error) {
|
2021-05-09 00:51:34 +00:00
|
|
|
// Get public IP address information
|
2022-04-16 21:58:42 +02:00
|
|
|
ipsToGetInfo := make([]net.IP, 0, len(servers))
|
|
|
|
|
for _, server := range servers {
|
|
|
|
|
ipsToGetInfo = append(ipsToGetInfo, server.IPs...)
|
2021-05-09 00:51:34 +00:00
|
|
|
}
|
|
|
|
|
ipsInfo, err := publicip.MultiInfo(ctx, client, ipsToGetInfo)
|
|
|
|
|
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
|
|
|
|
|
}
|