hotfix(publicip): revert back JSON to public_ip
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
package ipinfo
|
||||
|
||||
import "net"
|
||||
import (
|
||||
"net"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
)
|
||||
|
||||
type Response struct {
|
||||
IP net.IP `json:"ip,omitempty"`
|
||||
@@ -14,9 +18,18 @@ type Response struct {
|
||||
Timezone string `json:"timezone,omitempty"`
|
||||
}
|
||||
|
||||
func (r Response) Copy() (copied Response) {
|
||||
copied = r
|
||||
copied.IP = make(net.IP, len(r.IP))
|
||||
copy(copied.IP, r.IP)
|
||||
return copied
|
||||
func (r *Response) ToPublicIPModel() (model models.PublicIP) {
|
||||
model = models.PublicIP{
|
||||
IP: make(net.IP, len(r.IP)),
|
||||
Region: r.Region,
|
||||
Country: r.Country,
|
||||
City: r.City,
|
||||
Hostname: r.Hostname,
|
||||
Location: r.Loc,
|
||||
Organization: r.Org,
|
||||
PostalCode: r.Postal,
|
||||
Timezone: r.Timezone,
|
||||
}
|
||||
copy(model.IP, r.IP)
|
||||
return model
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package publicip
|
||||
|
||||
import "github.com/qdm12/gluetun/internal/publicip/ipinfo"
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
)
|
||||
|
||||
func (l *Loop) GetData() (data ipinfo.Response) {
|
||||
func (l *Loop) GetData() (data models.PublicIP) {
|
||||
return l.state.GetData()
|
||||
}
|
||||
|
||||
func (l *Loop) SetData(data ipinfo.Response) {
|
||||
func (l *Loop) SetData(data models.PublicIP) {
|
||||
l.state.SetData(data)
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"os"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/publicip/ipinfo"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
)
|
||||
|
||||
func (l *Loop) Run(ctx context.Context, done chan<- struct{}) {
|
||||
@@ -21,7 +21,7 @@ func (l *Loop) Run(ctx context.Context, done chan<- struct{}) {
|
||||
getCtx, getCancel := context.WithCancel(ctx)
|
||||
defer getCancel()
|
||||
|
||||
resultCh := make(chan ipinfo.Response)
|
||||
resultCh := make(chan models.PublicIP)
|
||||
errorCh := make(chan error)
|
||||
go func() {
|
||||
result, err := l.fetcher.FetchInfo(getCtx, nil)
|
||||
@@ -31,7 +31,7 @@ func (l *Loop) Run(ctx context.Context, done chan<- struct{}) {
|
||||
}
|
||||
return
|
||||
}
|
||||
resultCh <- result
|
||||
resultCh <- result.ToPublicIPModel()
|
||||
}()
|
||||
|
||||
if l.userTrigger {
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
package state
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/publicip/ipinfo"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
)
|
||||
|
||||
func (s *State) GetData() (data ipinfo.Response) {
|
||||
func (s *State) GetData() (data models.PublicIP) {
|
||||
s.ipDataMu.RLock()
|
||||
defer s.ipDataMu.RUnlock()
|
||||
return s.ipData.Copy()
|
||||
}
|
||||
|
||||
func (s *State) SetData(data ipinfo.Response) {
|
||||
func (s *State) SetData(data models.PublicIP) {
|
||||
s.ipDataMu.Lock()
|
||||
defer s.ipDataMu.Unlock()
|
||||
s.ipData = data.Copy()
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/publicip/ipinfo"
|
||||
)
|
||||
|
||||
func New(statusApplier StatusApplier,
|
||||
@@ -25,7 +24,7 @@ type State struct {
|
||||
settings settings.PublicIP
|
||||
settingsMu sync.RWMutex
|
||||
|
||||
ipData ipinfo.Response
|
||||
ipData models.PublicIP
|
||||
ipDataMu sync.RWMutex
|
||||
|
||||
updateTicker chan<- struct{}
|
||||
|
||||
Reference in New Issue
Block a user