chore(updater): internal/updater/loop subpackage
- Do not export updater interface - Export updater struct - Define local interfaces where needed - More restrictive updater loop interface in http control server - Inject `Updater` into updater loop as an interface
This commit is contained in:
@@ -9,7 +9,6 @@ import (
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/portforward"
|
||||
"github.com/qdm12/gluetun/internal/publicip"
|
||||
"github.com/qdm12/gluetun/internal/updater"
|
||||
"github.com/qdm12/gluetun/internal/vpn"
|
||||
)
|
||||
|
||||
@@ -18,7 +17,7 @@ func newHandler(ctx context.Context, logger infoWarner, logging bool,
|
||||
vpnLooper vpn.Looper,
|
||||
pfGetter portforward.Getter,
|
||||
unboundLooper dns.Looper,
|
||||
updaterLooper updater.Looper,
|
||||
updaterLooper UpdaterLooper,
|
||||
publicIPLooper publicip.Looper,
|
||||
) http.Handler {
|
||||
handler := &handler{}
|
||||
|
||||
@@ -6,12 +6,11 @@ import (
|
||||
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/dns"
|
||||
"github.com/qdm12/gluetun/internal/updater"
|
||||
"github.com/qdm12/gluetun/internal/vpn"
|
||||
)
|
||||
|
||||
func newHandlerV0(ctx context.Context, logger infoWarner,
|
||||
vpn vpn.Looper, dns dns.Looper, updater updater.Looper) http.Handler {
|
||||
vpn vpn.Looper, dns dns.Looper, updater UpdaterLooper) http.Handler {
|
||||
return &handlerV0{
|
||||
ctx: ctx,
|
||||
logger: logger,
|
||||
@@ -26,7 +25,7 @@ type handlerV0 struct {
|
||||
logger infoWarner
|
||||
vpn vpn.Looper
|
||||
dns dns.Looper
|
||||
updater updater.Looper
|
||||
updater UpdaterLooper
|
||||
}
|
||||
|
||||
func (h *handlerV0) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
@@ -10,14 +10,13 @@ import (
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/portforward"
|
||||
"github.com/qdm12/gluetun/internal/publicip"
|
||||
"github.com/qdm12/gluetun/internal/updater"
|
||||
"github.com/qdm12/gluetun/internal/vpn"
|
||||
)
|
||||
|
||||
func New(ctx context.Context, address string, logEnabled bool, logger Logger,
|
||||
buildInfo models.BuildInformation, openvpnLooper vpn.Looper,
|
||||
pfGetter portforward.Getter, unboundLooper dns.Looper,
|
||||
updaterLooper updater.Looper, publicIPLooper publicip.Looper) (server httpserver.Runner, err error) {
|
||||
updaterLooper UpdaterLooper, publicIPLooper publicip.Looper) (server httpserver.Runner, err error) {
|
||||
handler := newHandler(ctx, logger, logEnabled, buildInfo,
|
||||
openvpnLooper, pfGetter, unboundLooper, updaterLooper, publicIPLooper)
|
||||
|
||||
|
||||
@@ -6,12 +6,20 @@ import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/updater"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
)
|
||||
|
||||
type UpdaterLooper interface {
|
||||
GetStatus() (status models.LoopStatus)
|
||||
SetStatus(ctx context.Context, status models.LoopStatus) (
|
||||
outcome string, err error)
|
||||
SetSettings(settings settings.Updater) (outcome string)
|
||||
}
|
||||
|
||||
func newUpdaterHandler(
|
||||
ctx context.Context,
|
||||
looper updater.Looper,
|
||||
looper UpdaterLooper,
|
||||
warner warner) http.Handler {
|
||||
return &updaterHandler{
|
||||
ctx: ctx,
|
||||
@@ -22,7 +30,7 @@ func newUpdaterHandler(
|
||||
|
||||
type updaterHandler struct {
|
||||
ctx context.Context //nolint:containedctx
|
||||
looper updater.Looper
|
||||
looper UpdaterLooper
|
||||
warner warner
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user