diff --git a/cmd/gluetun/main.go b/cmd/gluetun/main.go index 6e75f4d9..b3734ea8 100644 --- a/cmd/gluetun/main.go +++ b/cmd/gluetun/main.go @@ -359,7 +359,7 @@ func _main(ctx context.Context, buildInfo models.BuildInformation, go publicIPLooper.RunRestartTicker(pubIPTickerCtx, pubIPTickerDone) tickersGroupHandler.Add(pubIPTickerHandler) - httpProxyLooper := httpproxy.NewLooper( + httpProxyLooper := httpproxy.NewLoop( logger.NewChild(logging.Settings{Prefix: "http proxy: "}), allSettings.HTTPProxy) httpProxyHandler, httpProxyCtx, httpProxyDone := goshutdown.NewGoRoutineHandler( diff --git a/internal/httpproxy/loop.go b/internal/httpproxy/loop.go index c7c01201..07bcaf2e 100644 --- a/internal/httpproxy/loop.go +++ b/internal/httpproxy/loop.go @@ -20,7 +20,7 @@ type Looper interface { SettingsGetterSetter } -type looper struct { +type Loop struct { statusManager loopstate.Manager state state.Manager // Other objects @@ -34,7 +34,7 @@ type looper struct { const defaultBackoffTime = 10 * time.Second -func NewLooper(logger logging.Logger, settings configuration.HTTPProxy) Looper { +func NewLoop(logger logging.Logger, settings configuration.HTTPProxy) *Loop { start := make(chan struct{}) running := make(chan models.LoopStatus) stop := make(chan struct{}) @@ -44,7 +44,7 @@ func NewLooper(logger logging.Logger, settings configuration.HTTPProxy) Looper { start, running, stop, stopped) state := state.New(statusManager, settings) - return &looper{ + return &Loop{ statusManager: statusManager, state: state, logger: logger, @@ -56,7 +56,7 @@ func NewLooper(logger logging.Logger, settings configuration.HTTPProxy) Looper { } } -func (l *looper) logAndWait(ctx context.Context, err error) { +func (l *Loop) logAndWait(ctx context.Context, err error) { l.logger.Error(err.Error()) l.logger.Info("retrying in " + l.backoffTime.String()) timer := time.NewTimer(l.backoffTime) diff --git a/internal/httpproxy/run.go b/internal/httpproxy/run.go index 0025d83f..4e52d1c8 100644 --- a/internal/httpproxy/run.go +++ b/internal/httpproxy/run.go @@ -11,12 +11,12 @@ type Runner interface { Run(ctx context.Context, done chan<- struct{}) } -func (l *looper) Run(ctx context.Context, done chan<- struct{}) { +func (l *Loop) Run(ctx context.Context, done chan<- struct{}) { defer close(done) crashed := false - if l.GetSettings().Enabled { + if l.state.GetSettings().Enabled { go func() { _, _ = l.statusManager.ApplyStatus(ctx, constants.Running) }() @@ -31,7 +31,7 @@ func (l *looper) Run(ctx context.Context, done chan<- struct{}) { for ctx.Err() == nil { runCtx, runCancel := context.WithCancel(ctx) - settings := l.GetSettings() + settings := l.state.GetSettings() address := fmt.Sprintf(":%d", settings.Port) server := New(runCtx, address, l.logger, settings.Stealth, settings.Log, settings.User, settings.Password) diff --git a/internal/httpproxy/settings.go b/internal/httpproxy/settings.go index 576ab488..6dbecd3a 100644 --- a/internal/httpproxy/settings.go +++ b/internal/httpproxy/settings.go @@ -9,11 +9,11 @@ import ( type SettingsGetterSetter = state.SettingsGetterSetter -func (l *looper) GetSettings() (settings configuration.HTTPProxy) { +func (l *Loop) GetSettings() (settings configuration.HTTPProxy) { return l.state.GetSettings() } -func (l *looper) SetSettings(ctx context.Context, settings configuration.HTTPProxy) ( +func (l *Loop) SetSettings(ctx context.Context, settings configuration.HTTPProxy) ( outcome string) { return l.state.SetSettings(ctx, settings) } diff --git a/internal/httpproxy/status.go b/internal/httpproxy/status.go index c0ff3bd8..461dc5b7 100644 --- a/internal/httpproxy/status.go +++ b/internal/httpproxy/status.go @@ -6,11 +6,11 @@ import ( "github.com/qdm12/gluetun/internal/models" ) -func (l *looper) GetStatus() (status models.LoopStatus) { +func (l *Loop) GetStatus() (status models.LoopStatus) { return l.statusManager.GetStatus() } -func (l *looper) ApplyStatus(ctx context.Context, status models.LoopStatus) ( +func (l *Loop) ApplyStatus(ctx context.Context, status models.LoopStatus) ( outcome string, err error) { return l.statusManager.ApplyStatus(ctx, status) }