chore(publicip): refactoring

- Exported `Fetcher` interface
- Inject `Fetcher` to publicip loop and updaters
- Get public IP and information at the same time
- Only query ipinfo.io
- Make `MultiInfo` part of the `Fetch` object
This commit is contained in:
Quentin McGaw
2022-06-12 00:09:01 +00:00
parent 45c9e780c0
commit 83b4a3fe55
19 changed files with 101 additions and 155 deletions

View File

@@ -3,19 +3,18 @@ package updater
import (
"context"
"net"
"net/http"
"github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/internal/publicip"
"github.com/qdm12/gluetun/internal/provider/common"
)
func setLocationInfo(ctx context.Context, client *http.Client, servers []models.Server) (err error) {
func setLocationInfo(ctx context.Context, fetcher common.IPFetcher, 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)
ipsInfo, err := fetcher.FetchMultiInfo(ctx, ipsToGetInfo)
if err != nil {
return err
}