Files
gluetun/internal/provider/privado/updater/location.go
Quentin McGaw ebd94723c1 chore(updater): incorporate FetchServers method in Provider interface
- Each provider interface can now fetch updated servers data
- Rename each provider updater subpackage name to `updater`
- Updater constructor does not take a settings struct
- Updater update method takes in a slice of provider strings
2022-06-09 23:47:41 +00:00

32 lines
699 B
Go

package updater
import (
"context"
"net"
"net/http"
"github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/internal/publicip"
)
func setLocationInfo(ctx context.Context, client *http.Client, servers []models.Server) (err error) {
// Get public IP address information
ipsToGetInfo := make([]net.IP, 0, len(servers))
for _, server := range servers {
ipsToGetInfo = append(ipsToGetInfo, server.IPs...)
}
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
}