Files
gluetun/internal/updater/providers/purevpn/hosttoserver.go
Quentin McGaw e8e7b83297 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
2021-05-08 00:59:42 +00:00

44 lines
916 B
Go

package purevpn
import (
"net"
"github.com/qdm12/gluetun/internal/models"
)
type hostToServer map[string]models.PurevpnServer
func (hts hostToServer) add(host string) {
// TODO set TCP and UDP compatibility, set hostname
hts[host] = models.PurevpnServer{}
}
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) {
for host, IPs := range hostToIPs {
server := hts[host]
server.IPs = IPs
hts[host] = server
}
for host, server := range hts {
if len(server.IPs) == 0 {
delete(hts, host)
}
}
}
func (hts hostToServer) toServersSlice() (servers []models.PurevpnServer) {
servers = make([]models.PurevpnServer, 0, len(hts))
for _, server := range hts {
servers = append(servers, server)
}
return servers
}