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:
@@ -9,13 +9,12 @@ import (
|
||||
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/updater/openvpn"
|
||||
"github.com/qdm12/gluetun/internal/updater/unzip"
|
||||
)
|
||||
|
||||
var ErrNotEnoughServers = errors.New("not enough servers found")
|
||||
|
||||
func GetServers(ctx context.Context, unzipper unzip.Unzipper, minServers int) (
|
||||
servers []models.Server, warnings []string, err error) {
|
||||
func (u *Updater) GetServers(ctx context.Context, minServers int) (
|
||||
servers []models.Server, err error) {
|
||||
zipURL := url.URL{
|
||||
Scheme: "https",
|
||||
Host: "www.perfect-privacy.com",
|
||||
@@ -28,9 +27,9 @@ func GetServers(ctx context.Context, unzipper unzip.Unzipper, minServers int) (
|
||||
values.Set("protocol", "udp") // all support both TCP and UDP
|
||||
zipURL.RawQuery = values.Encode()
|
||||
|
||||
contents, err := unzipper.FetchAndExtract(ctx, zipURL.String())
|
||||
contents, err := u.unzipper.FetchAndExtract(ctx, zipURL.String())
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cts := make(cityToServer)
|
||||
@@ -38,12 +37,12 @@ func GetServers(ctx context.Context, unzipper unzip.Unzipper, minServers int) (
|
||||
for fileName, content := range contents {
|
||||
err := addServerFromOvpn(cts, fileName, content)
|
||||
if err != nil {
|
||||
warnings = append(warnings, fileName+": "+err.Error())
|
||||
u.warner.Warn(err.Error() + " in " + fileName)
|
||||
}
|
||||
}
|
||||
|
||||
if len(cts) < minServers {
|
||||
return nil, warnings, fmt.Errorf("%w: %d and expected at least %d",
|
||||
return nil, fmt.Errorf("%w: %d and expected at least %d",
|
||||
ErrNotEnoughServers, len(cts), minServers)
|
||||
}
|
||||
|
||||
@@ -51,7 +50,7 @@ func GetServers(ctx context.Context, unzipper unzip.Unzipper, minServers int) (
|
||||
|
||||
sortServers(servers)
|
||||
|
||||
return servers, warnings, nil
|
||||
return servers, nil
|
||||
}
|
||||
|
||||
func addServerFromOvpn(cts cityToServer,
|
||||
|
||||
19
internal/provider/perfectprivacy/updater/updater.go
Normal file
19
internal/provider/perfectprivacy/updater/updater.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package perfectprivacy
|
||||
|
||||
import "github.com/qdm12/gluetun/internal/updater/unzip"
|
||||
|
||||
type Updater struct {
|
||||
unzipper unzip.Unzipper
|
||||
warner Warner
|
||||
}
|
||||
|
||||
type Warner interface {
|
||||
Warn(s string)
|
||||
}
|
||||
|
||||
func New(unzipper unzip.Unzipper, warner Warner) *Updater {
|
||||
return &Updater{
|
||||
unzipper: unzipper,
|
||||
warner: warner,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user