chore(surfshark): add package internal/provider/surshark/server
- Merge `internal/models/location.go` and `internal/constants/surfshark.go` into `internal/provider/surfshark/servers/locationdata.go`
This commit is contained in:
@@ -7,7 +7,7 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/provider/surfshark/servers"
|
||||
)
|
||||
|
||||
// Note: no multi-hop and some servers are missing from their API.
|
||||
@@ -18,7 +18,7 @@ func addServersFromAPI(ctx context.Context, client *http.Client,
|
||||
return err
|
||||
}
|
||||
|
||||
locationData := constants.SurfsharkLocationData()
|
||||
locationData := servers.LocationData()
|
||||
hostToLocation := hostToLocation(locationData)
|
||||
|
||||
const tcp, udp = true, true
|
||||
|
||||
@@ -4,15 +4,15 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/surfshark/servers"
|
||||
)
|
||||
|
||||
var (
|
||||
errHostnameNotFound = errors.New("hostname not found in hostname to location mapping")
|
||||
)
|
||||
|
||||
func getHostInformation(host string, hostnameToLocation map[string]models.SurfsharkLocationData) (
|
||||
data models.SurfsharkLocationData, err error) {
|
||||
func getHostInformation(host string, hostnameToLocation map[string]servers.ServerLocation) (
|
||||
data servers.ServerLocation, err error) {
|
||||
locationData, ok := hostnameToLocation[host]
|
||||
if !ok {
|
||||
return locationData, fmt.Errorf("%w: %s", errHostnameNotFound, host)
|
||||
@@ -21,9 +21,9 @@ func getHostInformation(host string, hostnameToLocation map[string]models.Surfsh
|
||||
return locationData, nil
|
||||
}
|
||||
|
||||
func hostToLocation(locationData []models.SurfsharkLocationData) (
|
||||
hostToLocation map[string]models.SurfsharkLocationData) {
|
||||
hostToLocation = make(map[string]models.SurfsharkLocationData, len(locationData))
|
||||
func hostToLocation(locationData []servers.ServerLocation) (
|
||||
hostToLocation map[string]servers.ServerLocation) {
|
||||
hostToLocation = make(map[string]servers.ServerLocation, len(locationData))
|
||||
for _, data := range locationData {
|
||||
hostToLocation[data.Hostname] = data
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package surfshark
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/provider/surfshark/servers"
|
||||
)
|
||||
|
||||
// getRemainingServers finds extra servers not found in the API or in the ZIP file.
|
||||
func getRemainingServers(hts hostToServer) {
|
||||
locationData := constants.SurfsharkLocationData()
|
||||
locationData := servers.LocationData()
|
||||
hostnameToLocationLeft := hostToLocation(locationData)
|
||||
for _, hostnameDone := range hts.toHostsSlice() {
|
||||
delete(hostnameToLocationLeft, hostnameDone)
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/provider/surfshark/servers"
|
||||
"github.com/qdm12/gluetun/internal/updater/openvpn"
|
||||
"github.com/qdm12/gluetun/internal/updater/unzip"
|
||||
)
|
||||
@@ -24,7 +24,7 @@ func addOpenVPNServersFromZip(ctx context.Context,
|
||||
hostnamesDoneSet[hostname] = struct{}{}
|
||||
}
|
||||
|
||||
locationData := constants.SurfsharkLocationData()
|
||||
locationData := servers.LocationData()
|
||||
hostToLocation := hostToLocation(locationData)
|
||||
|
||||
for fileName, content := range contents {
|
||||
|
||||
Reference in New Issue
Block a user