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:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -49,20 +49,29 @@ 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 ctxErr := ctx.Err(); ctxErr != nil {
|
||||
return allServers, ctxErr
|
||||
}
|
||||
u.logger.Error(err.Error())
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user