Maint: rework publicip package

- Use loopstate package
- Loop interface composition
- Return concrete struct from constructors
- Split into more files
- Add publicip/state package
This commit is contained in:
Quentin McGaw (laptop)
2021-07-24 19:49:11 +00:00
parent c8ad9b942a
commit 8d512852a4
14 changed files with 427 additions and 371 deletions

View File

@@ -0,0 +1,38 @@
package state
import (
"net"
"sync"
"github.com/qdm12/gluetun/internal/configuration"
"github.com/qdm12/gluetun/internal/loopstate"
)
var _ Manager = (*State)(nil)
type Manager interface {
SettingsGetterSetter
PublicIPGetSetter
}
func New(statusApplier loopstate.Applier,
settings configuration.PublicIP,
updateTicker chan<- struct{}) *State {
return &State{
statusApplier: statusApplier,
settings: settings,
updateTicker: updateTicker,
}
}
type State struct {
statusApplier loopstate.Applier
settings configuration.PublicIP
settingsMu sync.RWMutex
publicIP net.IP
publicIPMu sync.RWMutex
updateTicker chan<- struct{}
}