Maintenance: refactor servers updater code

- Require at least 80% of number of servers now to pass
- Each provider is in its own package with a common structure
- Unzip package with unzipper interface
- Openvpn package with extraction and download functions
This commit is contained in:
Quentin McGaw
2021-05-08 00:59:42 +00:00
parent 442340dcf2
commit e8e7b83297
107 changed files with 3778 additions and 2374 deletions

View File

@@ -0,0 +1,47 @@
// Package windscribe contains code to obtain the server information
// for the Windscribe provider.
package windscribe
import (
"context"
"errors"
"fmt"
"net/http"
"github.com/qdm12/gluetun/internal/models"
)
var ErrNotEnoughServers = errors.New("not enough servers found")
func GetServers(ctx context.Context, client *http.Client, minServers int) (
servers []models.WindscribeServer, err error) {
data, err := fetchAPI(ctx, client)
if err != nil {
return nil, err
}
for _, regionData := range data.Data {
region := regionData.Region
for _, group := range regionData.Groups {
city := group.City
for _, node := range group.Nodes {
server := models.WindscribeServer{
Region: region,
City: city,
Hostname: node.Hostname,
IP: node.OpenvpnIP,
}
servers = append(servers, server)
}
}
}
if len(servers) < minServers {
return nil, fmt.Errorf("%w: %d and expected at least %d",
ErrNotEnoughServers, len(servers), minServers)
}
sortServers(servers)
return servers, nil
}