Fix linting errors
This commit is contained in:
@@ -3,6 +3,7 @@ package updater
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
@@ -32,6 +33,11 @@ func (u *updater) updateNordvpn(ctx context.Context) (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
var (
|
||||
ErrNoIDInServerName = errors.New("no ID in server name")
|
||||
ErrInvalidIDInServerName = errors.New("invalid ID in server name")
|
||||
)
|
||||
|
||||
func findNordvpnServers(ctx context.Context, client network.Client) (
|
||||
servers []models.NordvpnServer, warnings []string, err error) {
|
||||
const url = "https://nordvpn.com/api/server"
|
||||
@@ -74,12 +80,12 @@ func findNordvpnServers(ctx context.Context, client network.Client) (
|
||||
}
|
||||
i := strings.IndexRune(jsonServer.Name, '#')
|
||||
if i < 0 {
|
||||
return nil, nil, fmt.Errorf("No ID in server name %q", jsonServer.Name)
|
||||
return nil, nil, fmt.Errorf("%w: %s", ErrNoIDInServerName, jsonServer.Name)
|
||||
}
|
||||
idString := jsonServer.Name[i+1:]
|
||||
idUint64, err := strconv.ParseUint(idString, 10, 16)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("Bad ID in server name %q", jsonServer.Name)
|
||||
return nil, nil, fmt.Errorf("%w: %s", ErrInvalidIDInServerName, jsonServer.Name)
|
||||
}
|
||||
server := models.NordvpnServer{
|
||||
Region: jsonServer.Country,
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"archive/zip"
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
@@ -13,6 +14,10 @@ import (
|
||||
"github.com/qdm12/golibs/network"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrBadStatusCode = errors.New("bad HTTP status code")
|
||||
)
|
||||
|
||||
func fetchAndExtractFiles(ctx context.Context, client network.Client, urls ...string) (
|
||||
contents map[string][]byte, err error) {
|
||||
contents = make(map[string][]byte)
|
||||
@@ -21,7 +26,7 @@ func fetchAndExtractFiles(ctx context.Context, client network.Client, urls ...st
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if status != http.StatusOK {
|
||||
return nil, fmt.Errorf("Getting %s results in HTTP status code %d", url, status)
|
||||
return nil, fmt.Errorf("%w: fetching url %s: %d", ErrBadStatusCode, url, status)
|
||||
}
|
||||
newContents, err := zipExtractAll(zipBytes)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user