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:
53
internal/updater/providers/privado/hosttoserver.go
Normal file
53
internal/updater/providers/privado/hosttoserver.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package privado
|
||||
|
||||
import (
|
||||
"net"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
)
|
||||
|
||||
type hostToServer map[string]models.PrivadoServer
|
||||
|
||||
func (hts hostToServer) add(host string) {
|
||||
server, ok := hts[host]
|
||||
if ok {
|
||||
return
|
||||
}
|
||||
server.Hostname = host
|
||||
hts[host] = server
|
||||
}
|
||||
|
||||
func (hts hostToServer) toHostsSlice() (hosts []string) {
|
||||
hosts = make([]string, 0, len(hts))
|
||||
for host := range hts {
|
||||
hosts = append(hosts, host)
|
||||
}
|
||||
return hosts
|
||||
}
|
||||
|
||||
func (hts hostToServer) adaptWithIPs(hostToIPs map[string][]net.IP) (
|
||||
warnings []string) {
|
||||
for host, IPs := range hostToIPs {
|
||||
if len(IPs) > 1 {
|
||||
warning := "more than one IP address found for host " + host
|
||||
warnings = append(warnings, warning)
|
||||
}
|
||||
server := hts[host]
|
||||
server.IP = IPs[0]
|
||||
hts[host] = server
|
||||
}
|
||||
for host, server := range hts {
|
||||
if server.IP == nil {
|
||||
delete(hts, host)
|
||||
}
|
||||
}
|
||||
return warnings
|
||||
}
|
||||
|
||||
func (hts hostToServer) toServersSlice() (servers []models.PrivadoServer) {
|
||||
servers = make([]models.PrivadoServer, 0, len(hts))
|
||||
for _, server := range hts {
|
||||
servers = append(servers, server)
|
||||
}
|
||||
return servers
|
||||
}
|
||||
Reference in New Issue
Block a user