chore(all): Providers containing all provider objects

- Share the same providers for updater and vpn
- Initialise all providers at start
- Get from `Providers` instead of constructing on every run
This commit is contained in:
Quentin McGaw
2022-06-10 00:47:56 +00:00
parent ebd94723c1
commit 0378fe4a7b
9 changed files with 136 additions and 112 deletions

View File

@@ -2,13 +2,9 @@ package vpn
import (
"context"
"net/http"
"time"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/constants/vpn"
"github.com/qdm12/gluetun/internal/provider"
"github.com/qdm12/gluetun/internal/updater/unzip"
"github.com/qdm12/log"
)
@@ -29,16 +25,10 @@ func (l *Loop) Run(ctx context.Context, done chan<- struct{}) {
return
}
// Updater only objects which are unused in this loop
updaterWarner := (log.LoggerInterface)(nil)
updaterClient := (*http.Client)(nil)
updaterUnzipper := (unzip.Unzipper)(nil)
for ctx.Err() == nil {
settings := l.state.GetSettings()
providerConf := provider.New(*settings.Provider.Name, l.storage, time.Now,
updaterWarner, updaterClient, updaterUnzipper)
providerConf := l.providers.Get(*settings.Provider.Name)
portForwarding := *settings.Provider.PortForwarding.Enabled
var vpnRunner vpnRunner