chore(publicip): less coupling with ipinfo.io

This commit is contained in:
Quentin McGaw
2024-02-13 11:11:10 +00:00
parent 6a6337b98f
commit cfca026621
14 changed files with 136 additions and 75 deletions

View File

@@ -10,7 +10,7 @@ import (
"github.com/qdm12/gluetun/internal/configuration/settings"
"github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/internal/publicip/ipinfo"
"github.com/qdm12/gluetun/internal/publicip/api"
)
type Loop struct {
@@ -103,7 +103,7 @@ func (l *Loop) run(runCtx context.Context, runDone chan<- struct{},
lastFetch = l.timeNow()
timerIsReadyToReset = l.updateTimer(*l.settings.Period, lastFetch, timer, timerIsReadyToReset)
if errors.Is(err, ipinfo.ErrTooManyRequests) {
if errors.Is(err, api.ErrTooManyRequests) {
continue
}
@@ -112,7 +112,7 @@ func (l *Loop) run(runCtx context.Context, runDone chan<- struct{},
l.logger.Info(message)
l.ipDataMutex.Lock()
l.ipData = result.ToPublicIPModel()
l.ipData = result
l.ipDataMutex.Unlock()
filepath := *l.settings.IPFilepath
@@ -123,7 +123,7 @@ func (l *Loop) run(runCtx context.Context, runDone chan<- struct{},
}
}
func (l *Loop) fetchIPData(ctx context.Context) (result ipinfo.Response, err error) {
func (l *Loop) fetchIPData(ctx context.Context) (result models.PublicIP, err error) {
// keep retrying since settings updates won't change the
// behavior of the following code.
const defaultBackoffTime = 5 * time.Second
@@ -135,7 +135,7 @@ func (l *Loop) fetchIPData(ctx context.Context) (result ipinfo.Response, err err
return result, nil
case ctx.Err() != nil:
return result, err
case errors.Is(err, ipinfo.ErrTooManyRequests):
case errors.Is(err, api.ErrTooManyRequests):
l.logger.Warn(err.Error() + "; not retrying.")
return result, err
}