Mullvad updater (#228)
* Add Mullvad to updater cli * Update hardcoded servers for Mullvad
This commit is contained in:
@@ -2,6 +2,7 @@ package updater
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
@@ -16,13 +17,15 @@ type updater struct {
|
||||
storage storage.Storage
|
||||
timeNow func() time.Time
|
||||
println func(s string)
|
||||
httpGet func(url string) (resp *http.Response, err error)
|
||||
}
|
||||
|
||||
func New(storage storage.Storage) Updater {
|
||||
func New(storage storage.Storage, httpClient *http.Client) Updater {
|
||||
return &updater{
|
||||
storage: storage,
|
||||
timeNow: time.Now,
|
||||
println: func(s string) { fmt.Println(s) },
|
||||
httpGet: httpClient.Get,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,6 +62,18 @@ func (u *updater) UpdateServers(options Options) error {
|
||||
allServers.PiaOld.Servers = servers
|
||||
}
|
||||
|
||||
if options.Mullvad {
|
||||
servers, err := u.findMullvadServers()
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot update Mullvad servers: %w", err)
|
||||
}
|
||||
if options.Stdout {
|
||||
u.println(stringifyMullvadServers(servers))
|
||||
}
|
||||
allServers.Mullvad.Timestamp = u.timeNow().Unix()
|
||||
allServers.Mullvad.Servers = servers
|
||||
}
|
||||
|
||||
if options.File {
|
||||
if err := u.storage.FlushToFile(allServers); err != nil {
|
||||
return fmt.Errorf("cannot update servers: %w", err)
|
||||
|
||||
Reference in New Issue
Block a user