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

@@ -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