chore(all): return concrete types, accept interfaces

- Remove exported interfaces unused locally
- Define interfaces to accept arguments
- Return concrete types, not interfaces
This commit is contained in:
Quentin McGaw
2022-06-11 01:34:30 +00:00
parent 0378fe4a7b
commit 578ef768ab
132 changed files with 594 additions and 935 deletions

View File

@@ -12,21 +12,11 @@ import (
"github.com/qdm12/gluetun/internal/updater"
)
type Looper interface {
Run(ctx context.Context, done chan<- struct{})
RunRestartTicker(ctx context.Context, done chan<- struct{})
GetStatus() (status models.LoopStatus)
SetStatus(ctx context.Context, status models.LoopStatus) (
outcome string, err error)
GetSettings() (settings settings.Updater)
SetSettings(settings settings.Updater) (outcome string)
}
type Updater interface {
UpdateServers(ctx context.Context, providers []string) (err error)
}
type looper struct {
type Loop struct {
state state
// Objects
updater Updater
@@ -52,9 +42,9 @@ type Logger interface {
Error(s string)
}
func NewLooper(settings settings.Updater, providers updater.Providers,
storage updater.Storage, client *http.Client, logger Logger) Looper {
return &looper{
func NewLoop(settings settings.Updater, providers updater.Providers,
storage updater.Storage, client *http.Client, logger Logger) *Loop {
return &Loop{
state: state{
status: constants.Stopped,
settings: settings,
@@ -72,7 +62,7 @@ func NewLooper(settings settings.Updater, providers updater.Providers,
}
}
func (l *looper) logAndWait(ctx context.Context, err error) {
func (l *Loop) logAndWait(ctx context.Context, err error) {
if err != nil {
l.logger.Error(err.Error())
}
@@ -88,7 +78,7 @@ func (l *looper) logAndWait(ctx context.Context, err error) {
}
}
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
select {
@@ -156,7 +146,7 @@ func (l *looper) Run(ctx context.Context, done chan<- struct{}) {
}
}
func (l *looper) RunRestartTicker(ctx context.Context, done chan<- struct{}) {
func (l *Loop) RunRestartTicker(ctx context.Context, done chan<- struct{}) {
defer close(done)
timer := time.NewTimer(time.Hour)
timer.Stop()