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()

View File

@@ -25,7 +25,7 @@ func (s *state) setStatusWithLock(status models.LoopStatus) {
s.status = status
}
func (l *looper) GetStatus() (status models.LoopStatus) {
func (l *Loop) GetStatus() (status models.LoopStatus) {
l.state.statusMu.RLock()
defer l.state.statusMu.RUnlock()
return l.state.status
@@ -33,7 +33,7 @@ func (l *looper) GetStatus() (status models.LoopStatus) {
var ErrInvalidStatus = errors.New("invalid status")
func (l *looper) SetStatus(ctx context.Context, status models.LoopStatus) (outcome string, err error) {
func (l *Loop) SetStatus(ctx context.Context, status models.LoopStatus) (outcome string, err error) {
l.state.statusMu.Lock()
defer l.state.statusMu.Unlock()
existingStatus := l.state.status
@@ -84,13 +84,13 @@ func (l *looper) SetStatus(ctx context.Context, status models.LoopStatus) (outco
}
}
func (l *looper) GetSettings() (settings settings.Updater) {
func (l *Loop) GetSettings() (settings settings.Updater) {
l.state.periodMu.RLock()
defer l.state.periodMu.RUnlock()
return l.state.settings
}
func (l *looper) SetSettings(settings settings.Updater) (outcome string) {
func (l *Loop) SetSettings(settings settings.Updater) (outcome string) {
l.state.periodMu.Lock()
defer l.state.periodMu.Unlock()
settingsUnchanged := reflect.DeepEqual(settings, l.state.settings)