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:
29
internal/dns/interfaces.go
Normal file
29
internal/dns/interfaces.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package dns
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/qdm12/dns/pkg/unbound"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
)
|
||||
|
||||
type Configurator interface {
|
||||
SetupFiles(ctx context.Context) error
|
||||
MakeUnboundConf(settings unbound.Settings) (err error)
|
||||
Start(ctx context.Context, verbosityDetailsLevel uint8) (
|
||||
stdoutLines, stderrLines chan string, waitError chan error, err error)
|
||||
Version(ctx context.Context) (version string, err error)
|
||||
}
|
||||
|
||||
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 settings.DNS)
|
||||
SetSettings(ctx context.Context, settings settings.DNS) (outcome string)
|
||||
}
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/qdm12/dns/pkg/blacklist"
|
||||
"github.com/qdm12/dns/pkg/unbound"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/dns/state"
|
||||
@@ -15,20 +14,10 @@ import (
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
)
|
||||
|
||||
var _ Looper = (*Loop)(nil)
|
||||
|
||||
type Looper interface {
|
||||
Runner
|
||||
RestartTickerRunner
|
||||
loopstate.Applier
|
||||
loopstate.Getter
|
||||
SettingsGetSetter
|
||||
}
|
||||
|
||||
type Loop struct {
|
||||
statusManager loopstate.Manager
|
||||
state state.Manager
|
||||
conf unbound.Configurator
|
||||
statusManager statusManager
|
||||
state stateManager
|
||||
conf Configurator
|
||||
resolvConf string
|
||||
blockBuilder blacklist.Builder
|
||||
client *http.Client
|
||||
@@ -46,7 +35,7 @@ type Loop struct {
|
||||
|
||||
const defaultBackoffTime = 10 * time.Second
|
||||
|
||||
func NewLoop(conf unbound.Configurator, settings settings.DNS,
|
||||
func NewLoop(conf Configurator, settings settings.DNS,
|
||||
client *http.Client, logger Logger) *Loop {
|
||||
start := make(chan struct{})
|
||||
running := make(chan models.LoopStatus)
|
||||
|
||||
@@ -7,10 +7,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)
|
||||
|
||||
|
||||
@@ -6,22 +6,8 @@ import (
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
)
|
||||
|
||||
type SettingsGetSetter interface {
|
||||
SettingsGetter
|
||||
SettingsSetter
|
||||
}
|
||||
|
||||
type SettingsGetter interface {
|
||||
GetSettings() (settings settings.DNS)
|
||||
}
|
||||
|
||||
func (l *Loop) GetSettings() (settings settings.DNS) { return l.state.GetSettings() }
|
||||
|
||||
type SettingsSetter interface {
|
||||
SetSettings(ctx context.Context, settings settings.DNS) (
|
||||
outcome string)
|
||||
}
|
||||
|
||||
func (l *Loop) SetSettings(ctx context.Context, settings settings.DNS) (
|
||||
outcome string) {
|
||||
return l.state.SetSettings(ctx, settings)
|
||||
|
||||
@@ -8,12 +8,6 @@ import (
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
)
|
||||
|
||||
type SettingsGetSetter interface {
|
||||
GetSettings() (settings settings.DNS)
|
||||
SetSettings(ctx context.Context,
|
||||
settings settings.DNS) (outcome string)
|
||||
}
|
||||
|
||||
func (s *State) GetSettings() (settings settings.DNS) {
|
||||
s.settingsMu.RLock()
|
||||
defer s.settingsMu.RUnlock()
|
||||
|
||||
@@ -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.DNS,
|
||||
updateTicker chan<- struct{}) *State {
|
||||
return &State{
|
||||
@@ -24,10 +19,15 @@ func New(statusApplier loopstate.Applier,
|
||||
}
|
||||
|
||||
type State struct {
|
||||
statusApplier loopstate.Applier
|
||||
statusApplier StatusApplier
|
||||
|
||||
settings settings.DNS
|
||||
settingsMu sync.RWMutex
|
||||
|
||||
updateTicker chan<- struct{}
|
||||
}
|
||||
|
||||
type StatusApplier interface {
|
||||
ApplyStatus(ctx context.Context, status models.LoopStatus) (
|
||||
outcome string, err error)
|
||||
}
|
||||
|
||||
@@ -7,10 +7,6 @@ import (
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
)
|
||||
|
||||
type RestartTickerRunner interface {
|
||||
RunRestartTicker(ctx context.Context, done chan<- struct{})
|
||||
}
|
||||
|
||||
func (l *Loop) RunRestartTicker(ctx context.Context, done chan<- struct{}) {
|
||||
defer close(done)
|
||||
// Timer that acts as a ticker
|
||||
|
||||
Reference in New Issue
Block a user