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:
@@ -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
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ func (u *Updater) FetchServers(ctx context.Context, minServers int) (
|
||||
|
||||
servers = hts.toServersSlice()
|
||||
|
||||
if err := setLocationInfo(ctx, u.client, servers); err != nil {
|
||||
if err := setLocationInfo(ctx, u.ipFetcher, servers); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
@@ -1,22 +1,20 @@
|
||||
package updater
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/provider/common"
|
||||
)
|
||||
|
||||
type Updater struct {
|
||||
client *http.Client
|
||||
ipFetcher common.IPFetcher
|
||||
unzipper common.Unzipper
|
||||
parallelResolver common.ParallelResolver
|
||||
warner common.Warner
|
||||
}
|
||||
|
||||
func New(client *http.Client, unzipper common.Unzipper,
|
||||
func New(ipFetcher common.IPFetcher, unzipper common.Unzipper,
|
||||
warner common.Warner, parallelResolver common.ParallelResolver) *Updater {
|
||||
return &Updater{
|
||||
client: client,
|
||||
ipFetcher: ipFetcher,
|
||||
unzipper: unzipper,
|
||||
parallelResolver: parallelResolver,
|
||||
warner: warner,
|
||||
|
||||
Reference in New Issue
Block a user