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:
@@ -12,18 +12,9 @@ import (
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
)
|
||||
|
||||
var _ Looper = (*Loop)(nil)
|
||||
|
||||
type Looper interface {
|
||||
Runner
|
||||
loopstate.Getter
|
||||
loopstate.Applier
|
||||
SettingsGetSetter
|
||||
}
|
||||
|
||||
type Loop struct {
|
||||
statusManager loopstate.Manager
|
||||
state state.Manager
|
||||
statusManager statusManager
|
||||
state StateManager
|
||||
// Other objects
|
||||
logger Logger
|
||||
// Internal channels and locks
|
||||
@@ -34,6 +25,18 @@ type Loop struct {
|
||||
backoffTime time.Duration
|
||||
}
|
||||
|
||||
type statusManager interface {
|
||||
GetStatus() (status models.LoopStatus)
|
||||
SetStatus(status models.LoopStatus)
|
||||
ApplyStatus(ctx context.Context, status models.LoopStatus) (
|
||||
outcome string, err error)
|
||||
}
|
||||
|
||||
type StateManager interface {
|
||||
GetSettings() settings.HTTPProxy
|
||||
SetSettings(ctx context.Context, settings settings.HTTPProxy) (outcome string)
|
||||
}
|
||||
|
||||
const defaultBackoffTime = 10 * time.Second
|
||||
|
||||
func NewLoop(logger Logger, settings settings.HTTPProxy) *Loop {
|
||||
|
||||
@@ -6,10 +6,6 @@ import (
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
)
|
||||
|
||||
type Runner interface {
|
||||
Run(ctx context.Context, done chan<- struct{})
|
||||
}
|
||||
|
||||
func (l *Loop) Run(ctx context.Context, done chan<- struct{}) {
|
||||
defer close(done)
|
||||
|
||||
|
||||
@@ -4,11 +4,8 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/httpproxy/state"
|
||||
)
|
||||
|
||||
type SettingsGetSetter = state.SettingsGetSetter
|
||||
|
||||
func (l *Loop) GetSettings() (settings settings.HTTPProxy) {
|
||||
return l.state.GetSettings()
|
||||
}
|
||||
|
||||
@@ -8,26 +8,12 @@ import (
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
)
|
||||
|
||||
type SettingsGetSetter interface {
|
||||
SettingsGetter
|
||||
SettingsSetter
|
||||
}
|
||||
|
||||
type SettingsGetter interface {
|
||||
GetSettings() (settings settings.HTTPProxy)
|
||||
}
|
||||
|
||||
func (s *State) GetSettings() (settings settings.HTTPProxy) {
|
||||
s.settingsMu.RLock()
|
||||
defer s.settingsMu.RUnlock()
|
||||
return s.settings
|
||||
}
|
||||
|
||||
type SettingsSetter interface {
|
||||
SetSettings(ctx context.Context,
|
||||
settings settings.HTTPProxy) (outcome string)
|
||||
}
|
||||
|
||||
func (s *State) SetSettings(ctx context.Context,
|
||||
settings settings.HTTPProxy) (outcome string) {
|
||||
s.settingsMu.Lock()
|
||||
|
||||
@@ -1,19 +1,14 @@
|
||||
package state
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/loopstate"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
)
|
||||
|
||||
var _ Manager = (*State)(nil)
|
||||
|
||||
type Manager interface {
|
||||
SettingsGetSetter
|
||||
}
|
||||
|
||||
func New(statusApplier loopstate.Applier,
|
||||
func New(statusApplier StatusApplier,
|
||||
settings settings.HTTPProxy) *State {
|
||||
return &State{
|
||||
statusApplier: statusApplier,
|
||||
@@ -22,7 +17,12 @@ func New(statusApplier loopstate.Applier,
|
||||
}
|
||||
|
||||
type State struct {
|
||||
statusApplier loopstate.Applier
|
||||
statusApplier StatusApplier
|
||||
settings settings.HTTPProxy
|
||||
settingsMu sync.RWMutex
|
||||
}
|
||||
|
||||
type StatusApplier interface {
|
||||
ApplyStatus(ctx context.Context, status models.LoopStatus) (
|
||||
outcome string, err error)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user