hotfix(publicip): revert back JSON to public_ip
This commit is contained in:
31
internal/models/publicip.go
Normal file
31
internal/models/publicip.go
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
import "net"
|
||||||
|
|
||||||
|
type PublicIP struct {
|
||||||
|
IP net.IP `json:"public_ip,omitempty"`
|
||||||
|
Region string `json:"region,omitempty"`
|
||||||
|
Country string `json:"country,omitempty"`
|
||||||
|
City string `json:"city,omitempty"`
|
||||||
|
Hostname string `json:"hostname,omitempty"`
|
||||||
|
Location string `json:"location,omitempty"`
|
||||||
|
Organization string `json:"organization,omitempty"`
|
||||||
|
PostalCode string `json:"postal_code,omitempty"`
|
||||||
|
Timezone string `json:"timezone,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *PublicIP) Copy() (publicIPCopy PublicIP) {
|
||||||
|
publicIPCopy = PublicIP{
|
||||||
|
IP: make(net.IP, len(p.IP)),
|
||||||
|
Region: p.Region,
|
||||||
|
Country: p.Country,
|
||||||
|
City: p.City,
|
||||||
|
Hostname: p.Hostname,
|
||||||
|
Location: p.Location,
|
||||||
|
Organization: p.Organization,
|
||||||
|
PostalCode: p.PostalCode,
|
||||||
|
Timezone: p.Timezone,
|
||||||
|
}
|
||||||
|
copy(publicIPCopy.IP, p.IP)
|
||||||
|
return publicIPCopy
|
||||||
|
}
|
||||||
@@ -1,6 +1,10 @@
|
|||||||
package ipinfo
|
package ipinfo
|
||||||
|
|
||||||
import "net"
|
import (
|
||||||
|
"net"
|
||||||
|
|
||||||
|
"github.com/qdm12/gluetun/internal/models"
|
||||||
|
)
|
||||||
|
|
||||||
type Response struct {
|
type Response struct {
|
||||||
IP net.IP `json:"ip,omitempty"`
|
IP net.IP `json:"ip,omitempty"`
|
||||||
@@ -14,9 +18,18 @@ type Response struct {
|
|||||||
Timezone string `json:"timezone,omitempty"`
|
Timezone string `json:"timezone,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Response) Copy() (copied Response) {
|
func (r *Response) ToPublicIPModel() (model models.PublicIP) {
|
||||||
copied = r
|
model = models.PublicIP{
|
||||||
copied.IP = make(net.IP, len(r.IP))
|
IP: make(net.IP, len(r.IP)),
|
||||||
copy(copied.IP, r.IP)
|
Region: r.Region,
|
||||||
return copied
|
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
|
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()
|
return l.state.GetData()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *Loop) SetData(data ipinfo.Response) {
|
func (l *Loop) SetData(data models.PublicIP) {
|
||||||
l.state.SetData(data)
|
l.state.SetData(data)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/constants"
|
"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{}) {
|
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)
|
getCtx, getCancel := context.WithCancel(ctx)
|
||||||
defer getCancel()
|
defer getCancel()
|
||||||
|
|
||||||
resultCh := make(chan ipinfo.Response)
|
resultCh := make(chan models.PublicIP)
|
||||||
errorCh := make(chan error)
|
errorCh := make(chan error)
|
||||||
go func() {
|
go func() {
|
||||||
result, err := l.fetcher.FetchInfo(getCtx, nil)
|
result, err := l.fetcher.FetchInfo(getCtx, nil)
|
||||||
@@ -31,7 +31,7 @@ func (l *Loop) Run(ctx context.Context, done chan<- struct{}) {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
resultCh <- result
|
resultCh <- result.ToPublicIPModel()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if l.userTrigger {
|
if l.userTrigger {
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
package state
|
package state
|
||||||
|
|
||||||
import (
|
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()
|
s.ipDataMu.RLock()
|
||||||
defer s.ipDataMu.RUnlock()
|
defer s.ipDataMu.RUnlock()
|
||||||
return s.ipData.Copy()
|
return s.ipData.Copy()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *State) SetData(data ipinfo.Response) {
|
func (s *State) SetData(data models.PublicIP) {
|
||||||
s.ipDataMu.Lock()
|
s.ipDataMu.Lock()
|
||||||
defer s.ipDataMu.Unlock()
|
defer s.ipDataMu.Unlock()
|
||||||
s.ipData = data.Copy()
|
s.ipData = data.Copy()
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import (
|
|||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||||
"github.com/qdm12/gluetun/internal/models"
|
"github.com/qdm12/gluetun/internal/models"
|
||||||
"github.com/qdm12/gluetun/internal/publicip/ipinfo"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func New(statusApplier StatusApplier,
|
func New(statusApplier StatusApplier,
|
||||||
@@ -25,7 +24,7 @@ type State struct {
|
|||||||
settings settings.PublicIP
|
settings settings.PublicIP
|
||||||
settingsMu sync.RWMutex
|
settingsMu sync.RWMutex
|
||||||
|
|
||||||
ipData ipinfo.Response
|
ipData models.PublicIP
|
||||||
ipDataMu sync.RWMutex
|
ipDataMu sync.RWMutex
|
||||||
|
|
||||||
updateTicker chan<- struct{}
|
updateTicker chan<- struct{}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import (
|
|||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||||
"github.com/qdm12/gluetun/internal/models"
|
"github.com/qdm12/gluetun/internal/models"
|
||||||
"github.com/qdm12/gluetun/internal/publicip/ipinfo"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type VPNLooper interface {
|
type VPNLooper interface {
|
||||||
@@ -26,5 +25,5 @@ type PortForwardedGetter interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type PublicIPLoop interface {
|
type PublicIPLoop interface {
|
||||||
GetData() (data ipinfo.Response)
|
GetData() (data models.PublicIP)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/publicip/ipinfo"
|
"github.com/qdm12/gluetun/internal/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (l *Loop) cleanup(ctx context.Context, pfEnabled bool) {
|
func (l *Loop) cleanup(ctx context.Context, pfEnabled bool) {
|
||||||
@@ -15,7 +15,7 @@ func (l *Loop) cleanup(ctx context.Context, pfEnabled bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
l.publicip.SetData(ipinfo.Response{}) // clear public IP address data
|
l.publicip.SetData(models.PublicIP{}) // clear public IP address data
|
||||||
|
|
||||||
if pfEnabled {
|
if pfEnabled {
|
||||||
const pfTimeout = 100 * time.Millisecond
|
const pfTimeout = 100 * time.Millisecond
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import (
|
|||||||
"github.com/qdm12/gluetun/internal/netlink"
|
"github.com/qdm12/gluetun/internal/netlink"
|
||||||
"github.com/qdm12/gluetun/internal/portforward"
|
"github.com/qdm12/gluetun/internal/portforward"
|
||||||
"github.com/qdm12/gluetun/internal/provider"
|
"github.com/qdm12/gluetun/internal/provider"
|
||||||
"github.com/qdm12/gluetun/internal/publicip/ipinfo"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Firewall interface {
|
type Firewall interface {
|
||||||
@@ -66,5 +65,5 @@ type DNSLoop interface {
|
|||||||
type PublicIPLoop interface {
|
type PublicIPLoop interface {
|
||||||
ApplyStatus(ctx context.Context, status models.LoopStatus) (
|
ApplyStatus(ctx context.Context, status models.LoopStatus) (
|
||||||
outcome string, err error)
|
outcome string, err error)
|
||||||
SetData(data ipinfo.Response)
|
SetData(data models.PublicIP)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user