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

@@ -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)
}

View File

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

View File

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

View File

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

View File

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

View File

@@ -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)
}

View File

@@ -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