chore(updater): common GetServers signature

- Log warnings when running outside of CLI mode
- Remove updater CLI bool setting
- Warnings are logged in updating functions
This commit is contained in:
Quentin McGaw
2022-05-28 20:58:50 +00:00
parent 381089ebdf
commit 90c6c8485b
50 changed files with 896 additions and 325 deletions

View File

@@ -6,33 +6,33 @@ import (
"context"
"errors"
"fmt"
"net/http"
"github.com/qdm12/gluetun/internal/constants/vpn"
"github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/internal/updater/resolver"
)
var ErrNotEnoughServers = errors.New("not enough servers found")
func GetServers(ctx context.Context, client *http.Client,
presolver resolver.Parallel, minServers int) (
servers []models.Server, warnings []string, err error) {
tcpHostToURL, udpHostToURL, err := getAllHostToURL(ctx, client)
func (u *Updater) GetServers(ctx context.Context, minServers int) (
servers []models.Server, err error) {
tcpHostToURL, udpHostToURL, err := getAllHostToURL(ctx, u.client)
if err != nil {
return nil, nil, err
return nil, err
}
hosts := getUniqueHosts(tcpHostToURL, udpHostToURL)
if len(hosts) < minServers {
return nil, nil, fmt.Errorf("%w: %d and expected at least %d",
return nil, fmt.Errorf("%w: %d and expected at least %d",
ErrNotEnoughServers, len(hosts), minServers)
}
hostToIPs, warnings, err := resolveHosts(ctx, presolver, hosts, minServers)
hostToIPs, warnings, err := resolveHosts(ctx, u.presolver, hosts, minServers)
for _, warning := range warnings {
u.warner.Warn(warning)
}
if err != nil {
return nil, warnings, err
return nil, err
}
servers = make([]models.Server, 0, len(hostToIPs))
@@ -66,5 +66,5 @@ func GetServers(ctx context.Context, client *http.Client,
sortServers(servers)
return servers, warnings, nil
return servers, nil
}