chore(settings): refactor settings processing (#756)
- Better settings tree structure logged using `qdm12/gotree` - Read settings from environment variables, then files, then secret files - Settings methods to default them, merge them and override them - `DNS_PLAINTEXT_ADDRESS` default changed to `127.0.0.1` to use DoT. Warning added if set to something else. - `HTTPPROXY_LISTENING_ADDRESS` instead of `HTTPPROXY_PORT` (with retro-compatibility)
This commit is contained in:
@@ -4,7 +4,7 @@ import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/loopstate"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
@@ -47,7 +47,7 @@ type Loop struct {
|
||||
const defaultBackoffTime = 5 * time.Second
|
||||
|
||||
func NewLoop(client *http.Client, logger Logger,
|
||||
settings configuration.PublicIP, puid, pgid int) *Loop {
|
||||
settings settings.PublicIP, puid, pgid int) *Loop {
|
||||
start := make(chan struct{})
|
||||
running := make(chan models.LoopStatus)
|
||||
stop := make(chan struct{})
|
||||
|
||||
@@ -52,7 +52,7 @@ func (l *Loop) Run(ctx context.Context, done chan<- struct{}) {
|
||||
case <-ctx.Done():
|
||||
getCancel()
|
||||
close(errorCh)
|
||||
filepath := l.state.GetSettings().IPFilepath
|
||||
filepath := *l.state.GetSettings().IPFilepath
|
||||
l.logger.Info("Removing ip file " + filepath)
|
||||
if err := os.Remove(filepath); err != nil {
|
||||
l.logger.Error(err.Error())
|
||||
@@ -83,7 +83,7 @@ func (l *Loop) Run(ctx context.Context, done chan<- struct{}) {
|
||||
result.SetIP(ip)
|
||||
l.state.SetData(result)
|
||||
|
||||
filepath := l.state.GetSettings().IPFilepath
|
||||
filepath := *l.state.GetSettings().IPFilepath
|
||||
err = persistPublicIP(filepath, ip.String(), l.puid, l.pgid)
|
||||
if err != nil {
|
||||
l.logger.Error(err.Error())
|
||||
|
||||
@@ -3,14 +3,14 @@ package publicip
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
)
|
||||
|
||||
func (l *Loop) GetSettings() (settings configuration.PublicIP) {
|
||||
func (l *Loop) GetSettings() (settings settings.PublicIP) {
|
||||
return l.state.GetSettings()
|
||||
}
|
||||
|
||||
func (l *Loop) SetSettings(ctx context.Context, settings configuration.PublicIP) (
|
||||
func (l *Loop) SetSettings(ctx context.Context, settings settings.PublicIP) (
|
||||
outcome string) {
|
||||
return l.state.SetSettings(ctx, settings)
|
||||
}
|
||||
|
||||
@@ -4,22 +4,22 @@ import (
|
||||
"context"
|
||||
"reflect"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
)
|
||||
|
||||
type SettingsGetSetter interface {
|
||||
GetSettings() (settings configuration.PublicIP)
|
||||
GetSettings() (settings settings.PublicIP)
|
||||
SetSettings(ctx context.Context,
|
||||
settings configuration.PublicIP) (outcome string)
|
||||
settings settings.PublicIP) (outcome string)
|
||||
}
|
||||
|
||||
func (s *State) GetSettings() (settings configuration.PublicIP) {
|
||||
func (s *State) GetSettings() (settings settings.PublicIP) {
|
||||
s.settingsMu.RLock()
|
||||
defer s.settingsMu.RUnlock()
|
||||
return s.settings
|
||||
}
|
||||
|
||||
func (s *State) SetSettings(ctx context.Context, settings configuration.PublicIP) (
|
||||
func (s *State) SetSettings(ctx context.Context, settings settings.PublicIP) (
|
||||
outcome string) {
|
||||
s.settingsMu.Lock()
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package state
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/loopstate"
|
||||
"github.com/qdm12/gluetun/internal/publicip/models"
|
||||
)
|
||||
@@ -16,7 +16,7 @@ type Manager interface {
|
||||
}
|
||||
|
||||
func New(statusApplier loopstate.Applier,
|
||||
settings configuration.PublicIP,
|
||||
settings settings.PublicIP,
|
||||
updateTicker chan<- struct{}) *State {
|
||||
return &State{
|
||||
statusApplier: statusApplier,
|
||||
@@ -28,7 +28,7 @@ func New(statusApplier loopstate.Applier,
|
||||
type State struct {
|
||||
statusApplier loopstate.Applier
|
||||
|
||||
settings configuration.PublicIP
|
||||
settings settings.PublicIP
|
||||
settingsMu sync.RWMutex
|
||||
|
||||
ipData models.IPInfoData
|
||||
|
||||
@@ -16,7 +16,7 @@ func (l *Loop) RunRestartTicker(ctx context.Context, done chan<- struct{}) {
|
||||
timer := time.NewTimer(time.Hour)
|
||||
timer.Stop() // 1 hour, cannot be a race condition
|
||||
timerIsStopped := true
|
||||
if period := l.state.GetSettings().Period; period > 0 {
|
||||
if period := *l.state.GetSettings().Period; period > 0 {
|
||||
timerIsStopped = false
|
||||
timer.Reset(period)
|
||||
}
|
||||
@@ -31,13 +31,13 @@ func (l *Loop) RunRestartTicker(ctx context.Context, done chan<- struct{}) {
|
||||
case <-timer.C:
|
||||
lastTick = l.timeNow()
|
||||
_, _ = l.ApplyStatus(ctx, constants.Running)
|
||||
timer.Reset(l.state.GetSettings().Period)
|
||||
timer.Reset(*l.state.GetSettings().Period)
|
||||
case <-l.updateTicker:
|
||||
if !timerIsStopped && !timer.Stop() {
|
||||
<-timer.C
|
||||
}
|
||||
timerIsStopped = true
|
||||
period := l.state.GetSettings().Period
|
||||
period := *l.state.GetSettings().Period
|
||||
if period == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user