From 1b2bcf901abdbe22c91031643c552d4df00de816 Mon Sep 17 00:00:00 2001 From: Quentin McGaw Date: Sat, 7 May 2022 19:12:29 +0000 Subject: [PATCH] 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` --- .../configuration/settings/surfshark_retro.go | 7 +++---- .../settings/validation/surfshark.go | 4 ++-- internal/models/location.go | 12 ------------ .../surfshark/servers/locationdata.go} | 19 +++++++++++++------ internal/updater/providers/surfshark/api.go | 4 ++-- .../updater/providers/surfshark/location.go | 12 ++++++------ .../updater/providers/surfshark/remaining.go | 4 ++-- internal/updater/providers/surfshark/zip.go | 4 ++-- 8 files changed, 30 insertions(+), 36 deletions(-) delete mode 100644 internal/models/location.go rename internal/{constants/surfshark.go => provider/surfshark/servers/locationdata.go} (98%) diff --git a/internal/configuration/settings/surfshark_retro.go b/internal/configuration/settings/surfshark_retro.go index 5ce8a01b..cb812c03 100644 --- a/internal/configuration/settings/surfshark_retro.go +++ b/internal/configuration/settings/surfshark_retro.go @@ -3,15 +3,14 @@ package settings import ( "strings" - "github.com/qdm12/gluetun/internal/constants" - "github.com/qdm12/gluetun/internal/models" + "github.com/qdm12/gluetun/internal/provider/surfshark/servers" ) func surfsharkRetroRegion(selection ServerSelection) ( updatedSelection ServerSelection) { - locationData := constants.SurfsharkLocationData() + locationData := servers.LocationData() - retroToLocation := make(map[string]models.SurfsharkLocationData, len(locationData)) + retroToLocation := make(map[string]servers.ServerLocation, len(locationData)) for _, data := range locationData { if data.RetroLoc == "" { continue diff --git a/internal/configuration/settings/validation/surfshark.go b/internal/configuration/settings/validation/surfshark.go index 91a76a2d..bdf81fbd 100644 --- a/internal/configuration/settings/validation/surfshark.go +++ b/internal/configuration/settings/validation/surfshark.go @@ -1,12 +1,12 @@ package validation import ( - "github.com/qdm12/gluetun/internal/constants" + "github.com/qdm12/gluetun/internal/provider/surfshark/servers" ) // TODO remove in v4. func SurfsharkRetroLocChoices() (choices []string) { - locationData := constants.SurfsharkLocationData() + locationData := servers.LocationData() choices = make([]string, 0, len(locationData)) seen := make(map[string]struct{}, len(locationData)) for _, data := range locationData { diff --git a/internal/models/location.go b/internal/models/location.go deleted file mode 100644 index 175a2570..00000000 --- a/internal/models/location.go +++ /dev/null @@ -1,12 +0,0 @@ -package models - -// SurfsharkLocationData is required to keep location data on Surfshark -// servers that are not obtained through their API. -type SurfsharkLocationData struct { - Region string - Country string - City string - RetroLoc string // TODO remove in v4 - Hostname string - MultiHop bool -} diff --git a/internal/constants/surfshark.go b/internal/provider/surfshark/servers/locationdata.go similarity index 98% rename from internal/constants/surfshark.go rename to internal/provider/surfshark/servers/locationdata.go index 07f348fa..dcfcab09 100644 --- a/internal/constants/surfshark.go +++ b/internal/provider/surfshark/servers/locationdata.go @@ -1,13 +1,20 @@ -package constants +package servers -import ( - "github.com/qdm12/gluetun/internal/models" -) +// LocationData is required to keep location data on Surfshark +// servers that are not obtained through their API. +type ServerLocation struct { + Region string + Country string + City string + RetroLoc string // TODO remove in v4 + Hostname string + MultiHop bool +} // TODO remove retroRegion and servers from API in v4. -func SurfsharkLocationData() (data []models.SurfsharkLocationData) { +func LocationData() (data []ServerLocation) { //nolint:lll - return []models.SurfsharkLocationData{ + return []ServerLocation{ {Region: "Asia Pacific", Country: "Australia", City: "Adelaide", RetroLoc: "Australia Adelaide", Hostname: "au-adl.prod.surfshark.com", MultiHop: false}, {Region: "Asia Pacific", Country: "Australia", City: "Brisbane", RetroLoc: "Australia Brisbane", Hostname: "au-bne.prod.surfshark.com", MultiHop: false}, {Region: "Asia Pacific", Country: "Australia", City: "Melbourne", RetroLoc: "Australia Melbourne", Hostname: "au-mel.prod.surfshark.com", MultiHop: false}, diff --git a/internal/updater/providers/surfshark/api.go b/internal/updater/providers/surfshark/api.go index 7dee7cb7..52462f99 100644 --- a/internal/updater/providers/surfshark/api.go +++ b/internal/updater/providers/surfshark/api.go @@ -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 diff --git a/internal/updater/providers/surfshark/location.go b/internal/updater/providers/surfshark/location.go index defc43cd..0b8aa622 100644 --- a/internal/updater/providers/surfshark/location.go +++ b/internal/updater/providers/surfshark/location.go @@ -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 } diff --git a/internal/updater/providers/surfshark/remaining.go b/internal/updater/providers/surfshark/remaining.go index b61f97bb..002122cd 100644 --- a/internal/updater/providers/surfshark/remaining.go +++ b/internal/updater/providers/surfshark/remaining.go @@ -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) diff --git a/internal/updater/providers/surfshark/zip.go b/internal/updater/providers/surfshark/zip.go index ff343212..cbc15ca9 100644 --- a/internal/updater/providers/surfshark/zip.go +++ b/internal/updater/providers/surfshark/zip.go @@ -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 {