Loops and HTTP control server rework (#308)

- CRUD REST HTTP server
- `/v1` HTTP server prefix
- Retrocompatible with older routes (redirects to v1 or handles the requests directly)
- DNS, Updater and Openvpn refactored to have a REST-like state with new methods to change their states synchronously
- Openvpn, Unbound and Updater status, see #287
This commit is contained in:
Quentin McGaw
2020-12-19 20:10:34 -05:00
committed by GitHub
parent d60d629105
commit 4257581f55
30 changed files with 1191 additions and 438 deletions

View File

@@ -7,6 +7,7 @@ import (
"time"
"github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/internal/settings"
"github.com/qdm12/golibs/logging"
"github.com/qdm12/golibs/network"
)
@@ -17,7 +18,7 @@ type Updater interface {
type updater struct {
// configuration
options Options
options settings.Updater
// state
servers models.AllServers
@@ -30,11 +31,12 @@ type updater struct {
client network.Client
}
func New(options Options, httpClient *http.Client, currentServers models.AllServers, logger logging.Logger) Updater {
if len(options.DNSAddress) == 0 {
options.DNSAddress = "1.1.1.1"
func New(settings settings.Updater, httpClient *http.Client,
currentServers models.AllServers, logger logging.Logger) Updater {
if len(settings.DNSAddress) == 0 {
settings.DNSAddress = "1.1.1.1"
}
resolver := newResolver(options.DNSAddress)
resolver := newResolver(settings.DNSAddress)
const clientTimeout = 10 * time.Second
return &updater{
logger: logger,
@@ -42,7 +44,7 @@ func New(options Options, httpClient *http.Client, currentServers models.AllServ
println: func(s string) { fmt.Println(s) },
lookupIP: newLookupIP(resolver),
client: network.NewClient(clientTimeout),
options: options,
options: settings,
servers: currentServers,
}
}