chore(updater): tiny code changes

- Remove unneeded ctx error check in cyberghost updating code
- Move global scope caser to function local scope
- Return error if updating a single provider in `UpdateServers`
- Add comments on different error paths in `UpdateServers`
This commit is contained in:
Quentin McGaw
2022-06-03 13:01:29 +00:00
parent 87c6ebe1c5
commit 0549326dfb
3 changed files with 17 additions and 13 deletions

View File

@@ -34,9 +34,5 @@ func resolveHosts(ctx context.Context, presolver resolver.Parallel,
return nil, err
}
if err := ctx.Err(); err != nil {
return nil, err
}
return hostToIPs, nil
}

View File

@@ -98,8 +98,7 @@ func (u *Updater) getServers(ctx context.Context, provider string,
panic("provider " + provider + " is unknown")
}
servers, err = providerUpdater.GetServers(ctx, minServers)
return servers, err
return providerUpdater.GetServers(ctx, minServers)
}
func (u *Updater) getProviderServers(provider string) (servers []models.Server) {

View File

@@ -49,21 +49,30 @@ func New(settings settings.Updater, httpClient *http.Client,
}
}
var caser = cases.Title(language.English) //nolint:gochecknoglobals
func (u *Updater) UpdateServers(ctx context.Context) (allServers models.AllServers, err error) {
caser := cases.Title(language.English)
for _, provider := range u.options.Providers {
u.logger.Info("updating " + caser.String(provider) + " servers...")
// TODO support servers offering only TCP or only UDP
// for NordVPN and PureVPN
err := u.updateProvider(ctx, provider)
if err != nil {
if err == nil {
continue
}
// return the only error for the single provider.
if len(u.options.Providers) == 1 {
return allServers, err
}
// stop updating the next providers if context is canceled.
if ctxErr := ctx.Err(); ctxErr != nil {
return allServers, ctxErr
}
// Log the error and continue updating the next provider.
u.logger.Error(err.Error())
}
}
return u.servers, nil
}