Maint: http proxy return concrete Loop struct

This commit is contained in:
Quentin McGaw (laptop)
2021-07-24 18:52:19 +00:00
parent 85540d96b6
commit 849dfee200
5 changed files with 12 additions and 12 deletions

View File

@@ -359,7 +359,7 @@ func _main(ctx context.Context, buildInfo models.BuildInformation,
go publicIPLooper.RunRestartTicker(pubIPTickerCtx, pubIPTickerDone) go publicIPLooper.RunRestartTicker(pubIPTickerCtx, pubIPTickerDone)
tickersGroupHandler.Add(pubIPTickerHandler) tickersGroupHandler.Add(pubIPTickerHandler)
httpProxyLooper := httpproxy.NewLooper( httpProxyLooper := httpproxy.NewLoop(
logger.NewChild(logging.Settings{Prefix: "http proxy: "}), logger.NewChild(logging.Settings{Prefix: "http proxy: "}),
allSettings.HTTPProxy) allSettings.HTTPProxy)
httpProxyHandler, httpProxyCtx, httpProxyDone := goshutdown.NewGoRoutineHandler( httpProxyHandler, httpProxyCtx, httpProxyDone := goshutdown.NewGoRoutineHandler(

View File

@@ -20,7 +20,7 @@ type Looper interface {
SettingsGetterSetter SettingsGetterSetter
} }
type looper struct { type Loop struct {
statusManager loopstate.Manager statusManager loopstate.Manager
state state.Manager state state.Manager
// Other objects // Other objects
@@ -34,7 +34,7 @@ type looper struct {
const defaultBackoffTime = 10 * time.Second 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{}) start := make(chan struct{})
running := make(chan models.LoopStatus) running := make(chan models.LoopStatus)
stop := make(chan struct{}) stop := make(chan struct{})
@@ -44,7 +44,7 @@ func NewLooper(logger logging.Logger, settings configuration.HTTPProxy) Looper {
start, running, stop, stopped) start, running, stop, stopped)
state := state.New(statusManager, settings) state := state.New(statusManager, settings)
return &looper{ return &Loop{
statusManager: statusManager, statusManager: statusManager,
state: state, state: state,
logger: logger, 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.Error(err.Error())
l.logger.Info("retrying in " + l.backoffTime.String()) l.logger.Info("retrying in " + l.backoffTime.String())
timer := time.NewTimer(l.backoffTime) timer := time.NewTimer(l.backoffTime)

View File

@@ -11,12 +11,12 @@ type Runner interface {
Run(ctx context.Context, done chan<- struct{}) 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) defer close(done)
crashed := false crashed := false
if l.GetSettings().Enabled { if l.state.GetSettings().Enabled {
go func() { go func() {
_, _ = l.statusManager.ApplyStatus(ctx, constants.Running) _, _ = l.statusManager.ApplyStatus(ctx, constants.Running)
}() }()
@@ -31,7 +31,7 @@ func (l *looper) Run(ctx context.Context, done chan<- struct{}) {
for ctx.Err() == nil { for ctx.Err() == nil {
runCtx, runCancel := context.WithCancel(ctx) runCtx, runCancel := context.WithCancel(ctx)
settings := l.GetSettings() settings := l.state.GetSettings()
address := fmt.Sprintf(":%d", settings.Port) address := fmt.Sprintf(":%d", settings.Port)
server := New(runCtx, address, l.logger, settings.Stealth, settings.Log, settings.User, settings.Password) server := New(runCtx, address, l.logger, settings.Stealth, settings.Log, settings.User, settings.Password)

View File

@@ -9,11 +9,11 @@ import (
type SettingsGetterSetter = state.SettingsGetterSetter type SettingsGetterSetter = state.SettingsGetterSetter
func (l *looper) GetSettings() (settings configuration.HTTPProxy) { func (l *Loop) GetSettings() (settings configuration.HTTPProxy) {
return l.state.GetSettings() 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) { outcome string) {
return l.state.SetSettings(ctx, settings) return l.state.SetSettings(ctx, settings)
} }

View File

@@ -6,11 +6,11 @@ import (
"github.com/qdm12/gluetun/internal/models" "github.com/qdm12/gluetun/internal/models"
) )
func (l *looper) GetStatus() (status models.LoopStatus) { func (l *Loop) GetStatus() (status models.LoopStatus) {
return l.statusManager.GetStatus() 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) { outcome string, err error) {
return l.statusManager.ApplyStatus(ctx, status) return l.statusManager.ApplyStatus(ctx, status)
} }