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
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := ctx.Err(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return hostToIPs, nil
|
return hostToIPs, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,8 +98,7 @@ func (u *Updater) getServers(ctx context.Context, provider string,
|
|||||||
panic("provider " + provider + " is unknown")
|
panic("provider " + provider + " is unknown")
|
||||||
}
|
}
|
||||||
|
|
||||||
servers, err = providerUpdater.GetServers(ctx, minServers)
|
return providerUpdater.GetServers(ctx, minServers)
|
||||||
return servers, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *Updater) getProviderServers(provider string) (servers []models.Server) {
|
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) {
|
func (u *Updater) UpdateServers(ctx context.Context) (allServers models.AllServers, err error) {
|
||||||
|
caser := cases.Title(language.English)
|
||||||
for _, provider := range u.options.Providers {
|
for _, provider := range u.options.Providers {
|
||||||
u.logger.Info("updating " + caser.String(provider) + " servers...")
|
u.logger.Info("updating " + caser.String(provider) + " servers...")
|
||||||
// TODO support servers offering only TCP or only UDP
|
// TODO support servers offering only TCP or only UDP
|
||||||
// for NordVPN and PureVPN
|
// for NordVPN and PureVPN
|
||||||
err := u.updateProvider(ctx, provider)
|
err := u.updateProvider(ctx, provider)
|
||||||
if err != nil {
|
if err == nil {
|
||||||
if ctxErr := ctx.Err(); ctxErr != nil {
|
continue
|
||||||
return allServers, ctxErr
|
|
||||||
}
|
|
||||||
u.logger.Error(err.Error())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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
|
return u.servers, nil
|
||||||
|
|||||||
Reference in New Issue
Block a user