chore(all): provider to servers map in allServers
- Simplify formatting CLI - Simplify updater code - Simplify filter choices for config validation - Simplify all servers deep copying - Custom JSON marshaling methods for `AllServers` - Simplify provider constructor switch - Simplify storage merging - Simplify storage reading and extraction - Simplify updating code
This commit is contained in:
@@ -8,7 +8,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants/providers"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/updater/resolver"
|
||||
"github.com/qdm12/gluetun/internal/updater/unzip"
|
||||
@@ -47,16 +46,17 @@ func New(settings settings.Updater, httpClient *http.Client,
|
||||
}
|
||||
}
|
||||
|
||||
type updateFunc func(ctx context.Context) (err error)
|
||||
|
||||
func (u *updater) UpdateServers(ctx context.Context) (allServers models.AllServers, err error) {
|
||||
for _, provider := range u.options.Providers {
|
||||
u.logger.Info("updating " + strings.Title(provider) + " servers...")
|
||||
updateProvider := u.getUpdateFunction(provider)
|
||||
|
||||
// TODO support servers offering only TCP or only UDP
|
||||
// for NordVPN and PureVPN
|
||||
err = updateProvider(ctx)
|
||||
warnings, err := u.updateProvider(ctx, provider)
|
||||
if *u.options.CLI {
|
||||
for _, warning := range warnings {
|
||||
u.logger.Warn(provider + ": " + warning)
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
if ctxErr := ctx.Err(); ctxErr != nil {
|
||||
return allServers, ctxErr
|
||||
@@ -67,52 +67,3 @@ func (u *updater) UpdateServers(ctx context.Context) (allServers models.AllServe
|
||||
|
||||
return u.servers, nil
|
||||
}
|
||||
|
||||
func (u *updater) getUpdateFunction(provider string) (updateFunction updateFunc) {
|
||||
switch provider {
|
||||
case providers.Custom:
|
||||
panic("cannot update custom provider")
|
||||
case providers.Cyberghost:
|
||||
return func(ctx context.Context) (err error) { return u.updateCyberghost(ctx) }
|
||||
case providers.Expressvpn:
|
||||
return func(ctx context.Context) (err error) { return u.updateExpressvpn(ctx) }
|
||||
case providers.Fastestvpn:
|
||||
return func(ctx context.Context) (err error) { return u.updateFastestvpn(ctx) }
|
||||
case providers.HideMyAss:
|
||||
return func(ctx context.Context) (err error) { return u.updateHideMyAss(ctx) }
|
||||
case providers.Ipvanish:
|
||||
return func(ctx context.Context) (err error) { return u.updateIpvanish(ctx) }
|
||||
case providers.Ivpn:
|
||||
return func(ctx context.Context) (err error) { return u.updateIvpn(ctx) }
|
||||
case providers.Mullvad:
|
||||
return func(ctx context.Context) (err error) { return u.updateMullvad(ctx) }
|
||||
case providers.Nordvpn:
|
||||
return func(ctx context.Context) (err error) { return u.updateNordvpn(ctx) }
|
||||
case providers.Perfectprivacy:
|
||||
return func(ctx context.Context) (err error) { return u.updatePerfectprivacy(ctx) }
|
||||
case providers.Privado:
|
||||
return func(ctx context.Context) (err error) { return u.updatePrivado(ctx) }
|
||||
case providers.PrivateInternetAccess:
|
||||
return func(ctx context.Context) (err error) { return u.updatePIA(ctx) }
|
||||
case providers.Privatevpn:
|
||||
return func(ctx context.Context) (err error) { return u.updatePrivatevpn(ctx) }
|
||||
case providers.Protonvpn:
|
||||
return func(ctx context.Context) (err error) { return u.updateProtonvpn(ctx) }
|
||||
case providers.Purevpn:
|
||||
return func(ctx context.Context) (err error) { return u.updatePurevpn(ctx) }
|
||||
case providers.Surfshark:
|
||||
return func(ctx context.Context) (err error) { return u.updateSurfshark(ctx) }
|
||||
case providers.Torguard:
|
||||
return func(ctx context.Context) (err error) { return u.updateTorguard(ctx) }
|
||||
case providers.VPNUnlimited:
|
||||
return func(ctx context.Context) (err error) { return u.updateVPNUnlimited(ctx) }
|
||||
case providers.Vyprvpn:
|
||||
return func(ctx context.Context) (err error) { return u.updateVyprvpn(ctx) }
|
||||
case providers.Wevpn:
|
||||
return func(ctx context.Context) (err error) { return u.updateWevpn(ctx) }
|
||||
case providers.Windscribe:
|
||||
return func(ctx context.Context) (err error) { return u.updateWindscribe(ctx) }
|
||||
default:
|
||||
panic("provider " + provider + " is unknown")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user