chore(settings): use github.com/qdm12/gosettings
This commit is contained in:
3
go.mod
3
go.mod
@@ -8,6 +8,7 @@ require (
|
|||||||
github.com/golang/mock v1.6.0
|
github.com/golang/mock v1.6.0
|
||||||
github.com/qdm12/dns v1.11.0
|
github.com/qdm12/dns v1.11.0
|
||||||
github.com/qdm12/golibs v0.0.0-20210822203818-5c568b0777b6
|
github.com/qdm12/golibs v0.0.0-20210822203818-5c568b0777b6
|
||||||
|
github.com/qdm12/gosettings v0.2.0
|
||||||
github.com/qdm12/goshutdown v0.3.0
|
github.com/qdm12/goshutdown v0.3.0
|
||||||
github.com/qdm12/gosplash v0.1.0
|
github.com/qdm12/gosplash v0.1.0
|
||||||
github.com/qdm12/gotree v0.2.0
|
github.com/qdm12/gotree v0.2.0
|
||||||
@@ -18,7 +19,7 @@ require (
|
|||||||
github.com/stretchr/testify v1.8.2
|
github.com/stretchr/testify v1.8.2
|
||||||
github.com/vishvananda/netlink v1.2.1-beta.2
|
github.com/vishvananda/netlink v1.2.1-beta.2
|
||||||
github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a
|
github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a
|
||||||
golang.org/x/exp v0.0.0-20230519143937-03e91628a987
|
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1
|
||||||
golang.org/x/net v0.10.0
|
golang.org/x/net v0.10.0
|
||||||
golang.org/x/sys v0.8.0
|
golang.org/x/sys v0.8.0
|
||||||
golang.org/x/text v0.9.0
|
golang.org/x/text v0.9.0
|
||||||
|
|||||||
4
go.sum
4
go.sum
@@ -91,6 +91,8 @@ github.com/qdm12/golibs v0.0.0-20210603202746-e5494e9c2ebb/go.mod h1:15RBzkun0i8
|
|||||||
github.com/qdm12/golibs v0.0.0-20210723175634-a75ca7fd74c2/go.mod h1:6aRbg4Z/bTbm9JfxsGXfWKHi7zsOvPfUTK1S5HuAFKg=
|
github.com/qdm12/golibs v0.0.0-20210723175634-a75ca7fd74c2/go.mod h1:6aRbg4Z/bTbm9JfxsGXfWKHi7zsOvPfUTK1S5HuAFKg=
|
||||||
github.com/qdm12/golibs v0.0.0-20210822203818-5c568b0777b6 h1:bge5AL7cjHJMPz+5IOz5yF01q/l8No6+lIEBieA8gMg=
|
github.com/qdm12/golibs v0.0.0-20210822203818-5c568b0777b6 h1:bge5AL7cjHJMPz+5IOz5yF01q/l8No6+lIEBieA8gMg=
|
||||||
github.com/qdm12/golibs v0.0.0-20210822203818-5c568b0777b6/go.mod h1:6aRbg4Z/bTbm9JfxsGXfWKHi7zsOvPfUTK1S5HuAFKg=
|
github.com/qdm12/golibs v0.0.0-20210822203818-5c568b0777b6/go.mod h1:6aRbg4Z/bTbm9JfxsGXfWKHi7zsOvPfUTK1S5HuAFKg=
|
||||||
|
github.com/qdm12/gosettings v0.2.0 h1:Q/4s0t8k9e3MSKMM5oMUIE3UGrdd+U2+qR8rTgiKRvA=
|
||||||
|
github.com/qdm12/gosettings v0.2.0/go.mod h1:GptXlJVLQxfWznSlgc+pNo3JGnp+f2AKEv0tq/U7igU=
|
||||||
github.com/qdm12/goshutdown v0.3.0 h1:pqBpJkdwlZlfTEx4QHtS8u8CXx6pG0fVo6S1N0MpSEM=
|
github.com/qdm12/goshutdown v0.3.0 h1:pqBpJkdwlZlfTEx4QHtS8u8CXx6pG0fVo6S1N0MpSEM=
|
||||||
github.com/qdm12/goshutdown v0.3.0/go.mod h1:EqZ46No00kCTZ5qzdd3qIzY6ayhMt24QI8Mh8LVQYmM=
|
github.com/qdm12/goshutdown v0.3.0/go.mod h1:EqZ46No00kCTZ5qzdd3qIzY6ayhMt24QI8Mh8LVQYmM=
|
||||||
github.com/qdm12/gosplash v0.1.0 h1:Sfl+zIjFZFP7b0iqf2l5UkmEY97XBnaKkH3FNY6Gf7g=
|
github.com/qdm12/gosplash v0.1.0 h1:Sfl+zIjFZFP7b0iqf2l5UkmEY97XBnaKkH3FNY6Gf7g=
|
||||||
@@ -152,6 +154,8 @@ golang.org/x/crypto v0.6.0 h1:qfktjS5LUO+fFKeJXZ+ikTRijMmljikvG68fpMMruSc=
|
|||||||
golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58=
|
golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58=
|
||||||
golang.org/x/exp v0.0.0-20230519143937-03e91628a987 h1:3xJIFvzUFbu4ls0BTBYcgbCGhA63eAOEMxIHugyXJqA=
|
golang.org/x/exp v0.0.0-20230519143937-03e91628a987 h1:3xJIFvzUFbu4ls0BTBYcgbCGhA63eAOEMxIHugyXJqA=
|
||||||
golang.org/x/exp v0.0.0-20230519143937-03e91628a987/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w=
|
golang.org/x/exp v0.0.0-20230519143937-03e91628a987/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w=
|
||||||
|
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 h1:k/i9J1pBpvlfR+9QsetwPyERsqu1GIbi967PQMq3Ivc=
|
||||||
|
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w=
|
||||||
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
|
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
|
||||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||||
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"net/netip"
|
"net/netip"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/configuration/settings/helpers"
|
"github.com/qdm12/gluetun/internal/configuration/settings/helpers"
|
||||||
|
"github.com/qdm12/gosettings"
|
||||||
"github.com/qdm12/gotree"
|
"github.com/qdm12/gotree"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -40,7 +41,7 @@ func (d DNS) validate() (err error) {
|
|||||||
func (d *DNS) Copy() (copied DNS) {
|
func (d *DNS) Copy() (copied DNS) {
|
||||||
return DNS{
|
return DNS{
|
||||||
ServerAddress: d.ServerAddress,
|
ServerAddress: d.ServerAddress,
|
||||||
KeepNameserver: helpers.CopyPointer(d.KeepNameserver),
|
KeepNameserver: gosettings.CopyPointer(d.KeepNameserver),
|
||||||
DoT: d.DoT.copy(),
|
DoT: d.DoT.copy(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -48,8 +49,8 @@ func (d *DNS) Copy() (copied DNS) {
|
|||||||
// mergeWith merges the other settings into any
|
// mergeWith merges the other settings into any
|
||||||
// unset field of the receiver settings object.
|
// unset field of the receiver settings object.
|
||||||
func (d *DNS) mergeWith(other DNS) {
|
func (d *DNS) mergeWith(other DNS) {
|
||||||
d.ServerAddress = helpers.MergeWithIP(d.ServerAddress, other.ServerAddress)
|
d.ServerAddress = gosettings.MergeWithValidator(d.ServerAddress, other.ServerAddress)
|
||||||
d.KeepNameserver = helpers.MergeWithPointer(d.KeepNameserver, other.KeepNameserver)
|
d.KeepNameserver = gosettings.MergeWithPointer(d.KeepNameserver, other.KeepNameserver)
|
||||||
d.DoT.mergeWith(other.DoT)
|
d.DoT.mergeWith(other.DoT)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,15 +58,15 @@ func (d *DNS) mergeWith(other DNS) {
|
|||||||
// settings object with any field set in the other
|
// settings object with any field set in the other
|
||||||
// settings.
|
// settings.
|
||||||
func (d *DNS) overrideWith(other DNS) {
|
func (d *DNS) overrideWith(other DNS) {
|
||||||
d.ServerAddress = helpers.OverrideWithIP(d.ServerAddress, other.ServerAddress)
|
d.ServerAddress = gosettings.OverrideWithValidator(d.ServerAddress, other.ServerAddress)
|
||||||
d.KeepNameserver = helpers.OverrideWithPointer(d.KeepNameserver, other.KeepNameserver)
|
d.KeepNameserver = gosettings.OverrideWithPointer(d.KeepNameserver, other.KeepNameserver)
|
||||||
d.DoT.overrideWith(other.DoT)
|
d.DoT.overrideWith(other.DoT)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DNS) setDefaults() {
|
func (d *DNS) setDefaults() {
|
||||||
localhost := netip.AddrFrom4([4]byte{127, 0, 0, 1})
|
localhost := netip.AddrFrom4([4]byte{127, 0, 0, 1})
|
||||||
d.ServerAddress = helpers.DefaultIP(d.ServerAddress, localhost)
|
d.ServerAddress = gosettings.DefaultValidator(d.ServerAddress, localhost)
|
||||||
d.KeepNameserver = helpers.DefaultPointer(d.KeepNameserver, false)
|
d.KeepNameserver = gosettings.DefaultPointer(d.KeepNameserver, false)
|
||||||
d.DoT.setDefaults()
|
d.DoT.setDefaults()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
|
|
||||||
"github.com/qdm12/dns/pkg/blacklist"
|
"github.com/qdm12/dns/pkg/blacklist"
|
||||||
"github.com/qdm12/gluetun/internal/configuration/settings/helpers"
|
"github.com/qdm12/gluetun/internal/configuration/settings/helpers"
|
||||||
|
"github.com/qdm12/gosettings"
|
||||||
"github.com/qdm12/gotree"
|
"github.com/qdm12/gotree"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -23,9 +24,9 @@ type DNSBlacklist struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *DNSBlacklist) setDefaults() {
|
func (b *DNSBlacklist) setDefaults() {
|
||||||
b.BlockMalicious = helpers.DefaultPointer(b.BlockMalicious, true)
|
b.BlockMalicious = gosettings.DefaultPointer(b.BlockMalicious, true)
|
||||||
b.BlockAds = helpers.DefaultPointer(b.BlockAds, false)
|
b.BlockAds = gosettings.DefaultPointer(b.BlockAds, false)
|
||||||
b.BlockSurveillance = helpers.DefaultPointer(b.BlockSurveillance, true)
|
b.BlockSurveillance = gosettings.DefaultPointer(b.BlockSurveillance, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
var hostRegex = regexp.MustCompile(`^([a-zA-Z0-9]|[a-zA-Z0-9_][a-zA-Z0-9\-_]{0,61}[a-zA-Z0-9_])(\.([a-zA-Z0-9]|[a-zA-Z0-9_][a-zA-Z0-9\-_]{0,61}[a-zA-Z0-9]))*$`) //nolint:lll
|
var hostRegex = regexp.MustCompile(`^([a-zA-Z0-9]|[a-zA-Z0-9_][a-zA-Z0-9\-_]{0,61}[a-zA-Z0-9_])(\.([a-zA-Z0-9]|[a-zA-Z0-9_][a-zA-Z0-9\-_]{0,61}[a-zA-Z0-9]))*$`) //nolint:lll
|
||||||
@@ -53,34 +54,34 @@ func (b DNSBlacklist) validate() (err error) {
|
|||||||
|
|
||||||
func (b DNSBlacklist) copy() (copied DNSBlacklist) {
|
func (b DNSBlacklist) copy() (copied DNSBlacklist) {
|
||||||
return DNSBlacklist{
|
return DNSBlacklist{
|
||||||
BlockMalicious: helpers.CopyPointer(b.BlockMalicious),
|
BlockMalicious: gosettings.CopyPointer(b.BlockMalicious),
|
||||||
BlockAds: helpers.CopyPointer(b.BlockAds),
|
BlockAds: gosettings.CopyPointer(b.BlockAds),
|
||||||
BlockSurveillance: helpers.CopyPointer(b.BlockSurveillance),
|
BlockSurveillance: gosettings.CopyPointer(b.BlockSurveillance),
|
||||||
AllowedHosts: helpers.CopySlice(b.AllowedHosts),
|
AllowedHosts: gosettings.CopySlice(b.AllowedHosts),
|
||||||
AddBlockedHosts: helpers.CopySlice(b.AddBlockedHosts),
|
AddBlockedHosts: gosettings.CopySlice(b.AddBlockedHosts),
|
||||||
AddBlockedIPs: helpers.CopySlice(b.AddBlockedIPs),
|
AddBlockedIPs: gosettings.CopySlice(b.AddBlockedIPs),
|
||||||
AddBlockedIPPrefixes: helpers.CopySlice(b.AddBlockedIPPrefixes),
|
AddBlockedIPPrefixes: gosettings.CopySlice(b.AddBlockedIPPrefixes),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *DNSBlacklist) mergeWith(other DNSBlacklist) {
|
func (b *DNSBlacklist) mergeWith(other DNSBlacklist) {
|
||||||
b.BlockMalicious = helpers.MergeWithPointer(b.BlockMalicious, other.BlockMalicious)
|
b.BlockMalicious = gosettings.MergeWithPointer(b.BlockMalicious, other.BlockMalicious)
|
||||||
b.BlockAds = helpers.MergeWithPointer(b.BlockAds, other.BlockAds)
|
b.BlockAds = gosettings.MergeWithPointer(b.BlockAds, other.BlockAds)
|
||||||
b.BlockSurveillance = helpers.MergeWithPointer(b.BlockSurveillance, other.BlockSurveillance)
|
b.BlockSurveillance = gosettings.MergeWithPointer(b.BlockSurveillance, other.BlockSurveillance)
|
||||||
b.AllowedHosts = helpers.MergeSlices(b.AllowedHosts, other.AllowedHosts)
|
b.AllowedHosts = helpers.MergeWithSlice(b.AllowedHosts, other.AllowedHosts)
|
||||||
b.AddBlockedHosts = helpers.MergeSlices(b.AddBlockedHosts, other.AddBlockedHosts)
|
b.AddBlockedHosts = gosettings.MergeWithSlice(b.AddBlockedHosts, other.AddBlockedHosts)
|
||||||
b.AddBlockedIPs = helpers.MergeSlices(b.AddBlockedIPs, other.AddBlockedIPs)
|
b.AddBlockedIPs = gosettings.MergeWithSlice(b.AddBlockedIPs, other.AddBlockedIPs)
|
||||||
b.AddBlockedIPPrefixes = helpers.MergeSlices(b.AddBlockedIPPrefixes, other.AddBlockedIPPrefixes)
|
b.AddBlockedIPPrefixes = gosettings.MergeWithSlice(b.AddBlockedIPPrefixes, other.AddBlockedIPPrefixes)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *DNSBlacklist) overrideWith(other DNSBlacklist) {
|
func (b *DNSBlacklist) overrideWith(other DNSBlacklist) {
|
||||||
b.BlockMalicious = helpers.OverrideWithPointer(b.BlockMalicious, other.BlockMalicious)
|
b.BlockMalicious = gosettings.OverrideWithPointer(b.BlockMalicious, other.BlockMalicious)
|
||||||
b.BlockAds = helpers.OverrideWithPointer(b.BlockAds, other.BlockAds)
|
b.BlockAds = gosettings.OverrideWithPointer(b.BlockAds, other.BlockAds)
|
||||||
b.BlockSurveillance = helpers.OverrideWithPointer(b.BlockSurveillance, other.BlockSurveillance)
|
b.BlockSurveillance = gosettings.OverrideWithPointer(b.BlockSurveillance, other.BlockSurveillance)
|
||||||
b.AllowedHosts = helpers.OverrideWithSlice(b.AllowedHosts, other.AllowedHosts)
|
b.AllowedHosts = gosettings.OverrideWithSlice(b.AllowedHosts, other.AllowedHosts)
|
||||||
b.AddBlockedHosts = helpers.OverrideWithSlice(b.AddBlockedHosts, other.AddBlockedHosts)
|
b.AddBlockedHosts = gosettings.OverrideWithSlice(b.AddBlockedHosts, other.AddBlockedHosts)
|
||||||
b.AddBlockedIPs = helpers.OverrideWithSlice(b.AddBlockedIPs, other.AddBlockedIPs)
|
b.AddBlockedIPs = gosettings.OverrideWithSlice(b.AddBlockedIPs, other.AddBlockedIPs)
|
||||||
b.AddBlockedIPPrefixes = helpers.OverrideWithSlice(b.AddBlockedIPPrefixes, other.AddBlockedIPPrefixes)
|
b.AddBlockedIPPrefixes = gosettings.OverrideWithSlice(b.AddBlockedIPPrefixes, other.AddBlockedIPPrefixes)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b DNSBlacklist) ToBlacklistFormat() (settings blacklist.BuilderSettings, err error) {
|
func (b DNSBlacklist) ToBlacklistFormat() (settings blacklist.BuilderSettings, err error) {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/configuration/settings/helpers"
|
"github.com/qdm12/gluetun/internal/configuration/settings/helpers"
|
||||||
|
"github.com/qdm12/gosettings"
|
||||||
"github.com/qdm12/gotree"
|
"github.com/qdm12/gotree"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -54,8 +55,8 @@ func (d DoT) validate() (err error) {
|
|||||||
|
|
||||||
func (d *DoT) copy() (copied DoT) {
|
func (d *DoT) copy() (copied DoT) {
|
||||||
return DoT{
|
return DoT{
|
||||||
Enabled: helpers.CopyPointer(d.Enabled),
|
Enabled: gosettings.CopyPointer(d.Enabled),
|
||||||
UpdatePeriod: helpers.CopyPointer(d.UpdatePeriod),
|
UpdatePeriod: gosettings.CopyPointer(d.UpdatePeriod),
|
||||||
Unbound: d.Unbound.copy(),
|
Unbound: d.Unbound.copy(),
|
||||||
Blacklist: d.Blacklist.copy(),
|
Blacklist: d.Blacklist.copy(),
|
||||||
}
|
}
|
||||||
@@ -64,8 +65,8 @@ func (d *DoT) copy() (copied DoT) {
|
|||||||
// mergeWith merges the other settings into any
|
// mergeWith merges the other settings into any
|
||||||
// unset field of the receiver settings object.
|
// unset field of the receiver settings object.
|
||||||
func (d *DoT) mergeWith(other DoT) {
|
func (d *DoT) mergeWith(other DoT) {
|
||||||
d.Enabled = helpers.MergeWithPointer(d.Enabled, other.Enabled)
|
d.Enabled = gosettings.MergeWithPointer(d.Enabled, other.Enabled)
|
||||||
d.UpdatePeriod = helpers.MergeWithPointer(d.UpdatePeriod, other.UpdatePeriod)
|
d.UpdatePeriod = gosettings.MergeWithPointer(d.UpdatePeriod, other.UpdatePeriod)
|
||||||
d.Unbound.mergeWith(other.Unbound)
|
d.Unbound.mergeWith(other.Unbound)
|
||||||
d.Blacklist.mergeWith(other.Blacklist)
|
d.Blacklist.mergeWith(other.Blacklist)
|
||||||
}
|
}
|
||||||
@@ -74,16 +75,16 @@ func (d *DoT) mergeWith(other DoT) {
|
|||||||
// settings object with any field set in the other
|
// settings object with any field set in the other
|
||||||
// settings.
|
// settings.
|
||||||
func (d *DoT) overrideWith(other DoT) {
|
func (d *DoT) overrideWith(other DoT) {
|
||||||
d.Enabled = helpers.OverrideWithPointer(d.Enabled, other.Enabled)
|
d.Enabled = gosettings.OverrideWithPointer(d.Enabled, other.Enabled)
|
||||||
d.UpdatePeriod = helpers.OverrideWithPointer(d.UpdatePeriod, other.UpdatePeriod)
|
d.UpdatePeriod = gosettings.OverrideWithPointer(d.UpdatePeriod, other.UpdatePeriod)
|
||||||
d.Unbound.overrideWith(other.Unbound)
|
d.Unbound.overrideWith(other.Unbound)
|
||||||
d.Blacklist.overrideWith(other.Blacklist)
|
d.Blacklist.overrideWith(other.Blacklist)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DoT) setDefaults() {
|
func (d *DoT) setDefaults() {
|
||||||
d.Enabled = helpers.DefaultPointer(d.Enabled, true)
|
d.Enabled = gosettings.DefaultPointer(d.Enabled, true)
|
||||||
const defaultUpdatePeriod = 24 * time.Hour
|
const defaultUpdatePeriod = 24 * time.Hour
|
||||||
d.UpdatePeriod = helpers.DefaultPointer(d.UpdatePeriod, defaultUpdatePeriod)
|
d.UpdatePeriod = gosettings.DefaultPointer(d.UpdatePeriod, defaultUpdatePeriod)
|
||||||
d.Unbound.setDefaults()
|
d.Unbound.setDefaults()
|
||||||
d.Blacklist.setDefaults()
|
d.Blacklist.setDefaults()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"net/netip"
|
"net/netip"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/configuration/settings/helpers"
|
"github.com/qdm12/gluetun/internal/configuration/settings/helpers"
|
||||||
|
"github.com/qdm12/gosettings"
|
||||||
"github.com/qdm12/gotree"
|
"github.com/qdm12/gotree"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -40,11 +41,11 @@ func hasZeroPort(ports []uint16) (has bool) {
|
|||||||
|
|
||||||
func (f *Firewall) copy() (copied Firewall) {
|
func (f *Firewall) copy() (copied Firewall) {
|
||||||
return Firewall{
|
return Firewall{
|
||||||
VPNInputPorts: helpers.CopySlice(f.VPNInputPorts),
|
VPNInputPorts: gosettings.CopySlice(f.VPNInputPorts),
|
||||||
InputPorts: helpers.CopySlice(f.InputPorts),
|
InputPorts: gosettings.CopySlice(f.InputPorts),
|
||||||
OutboundSubnets: helpers.CopySlice(f.OutboundSubnets),
|
OutboundSubnets: gosettings.CopySlice(f.OutboundSubnets),
|
||||||
Enabled: helpers.CopyPointer(f.Enabled),
|
Enabled: gosettings.CopyPointer(f.Enabled),
|
||||||
Debug: helpers.CopyPointer(f.Debug),
|
Debug: gosettings.CopyPointer(f.Debug),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,27 +54,27 @@ func (f *Firewall) copy() (copied Firewall) {
|
|||||||
// It merges values of slices together, even if they
|
// It merges values of slices together, even if they
|
||||||
// are set in the receiver settings.
|
// are set in the receiver settings.
|
||||||
func (f *Firewall) mergeWith(other Firewall) {
|
func (f *Firewall) mergeWith(other Firewall) {
|
||||||
f.VPNInputPorts = helpers.MergeSlices(f.VPNInputPorts, other.VPNInputPorts)
|
f.VPNInputPorts = gosettings.MergeWithSlice(f.VPNInputPorts, other.VPNInputPorts)
|
||||||
f.InputPorts = helpers.MergeSlices(f.InputPorts, other.InputPorts)
|
f.InputPorts = gosettings.MergeWithSlice(f.InputPorts, other.InputPorts)
|
||||||
f.OutboundSubnets = helpers.MergeSlices(f.OutboundSubnets, other.OutboundSubnets)
|
f.OutboundSubnets = gosettings.MergeWithSlice(f.OutboundSubnets, other.OutboundSubnets)
|
||||||
f.Enabled = helpers.MergeWithPointer(f.Enabled, other.Enabled)
|
f.Enabled = gosettings.MergeWithPointer(f.Enabled, other.Enabled)
|
||||||
f.Debug = helpers.MergeWithPointer(f.Debug, other.Debug)
|
f.Debug = gosettings.MergeWithPointer(f.Debug, other.Debug)
|
||||||
}
|
}
|
||||||
|
|
||||||
// overrideWith overrides fields of the receiver
|
// overrideWith overrides fields of the receiver
|
||||||
// settings object with any field set in the other
|
// settings object with any field set in the other
|
||||||
// settings.
|
// settings.
|
||||||
func (f *Firewall) overrideWith(other Firewall) {
|
func (f *Firewall) overrideWith(other Firewall) {
|
||||||
f.VPNInputPorts = helpers.OverrideWithSlice(f.VPNInputPorts, other.VPNInputPorts)
|
f.VPNInputPorts = gosettings.OverrideWithSlice(f.VPNInputPorts, other.VPNInputPorts)
|
||||||
f.InputPorts = helpers.OverrideWithSlice(f.InputPorts, other.InputPorts)
|
f.InputPorts = gosettings.OverrideWithSlice(f.InputPorts, other.InputPorts)
|
||||||
f.OutboundSubnets = helpers.OverrideWithSlice(f.OutboundSubnets, other.OutboundSubnets)
|
f.OutboundSubnets = gosettings.OverrideWithSlice(f.OutboundSubnets, other.OutboundSubnets)
|
||||||
f.Enabled = helpers.OverrideWithPointer(f.Enabled, other.Enabled)
|
f.Enabled = gosettings.OverrideWithPointer(f.Enabled, other.Enabled)
|
||||||
f.Debug = helpers.OverrideWithPointer(f.Debug, other.Debug)
|
f.Debug = gosettings.OverrideWithPointer(f.Debug, other.Debug)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Firewall) setDefaults() {
|
func (f *Firewall) setDefaults() {
|
||||||
f.Enabled = helpers.DefaultPointer(f.Enabled, true)
|
f.Enabled = gosettings.DefaultPointer(f.Enabled, true)
|
||||||
f.Debug = helpers.DefaultPointer(f.Debug, false)
|
f.Debug = gosettings.DefaultPointer(f.Debug, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f Firewall) String() string {
|
func (f Firewall) String() string {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/configuration/settings/helpers"
|
"github.com/qdm12/gosettings"
|
||||||
"github.com/qdm12/gotree"
|
"github.com/qdm12/gotree"
|
||||||
"github.com/qdm12/govalid/address"
|
"github.com/qdm12/govalid/address"
|
||||||
)
|
)
|
||||||
@@ -65,11 +65,11 @@ func (h *Health) copy() (copied Health) {
|
|||||||
// MergeWith merges the other settings into any
|
// MergeWith merges the other settings into any
|
||||||
// unset field of the receiver settings object.
|
// unset field of the receiver settings object.
|
||||||
func (h *Health) MergeWith(other Health) {
|
func (h *Health) MergeWith(other Health) {
|
||||||
h.ServerAddress = helpers.MergeWithString(h.ServerAddress, other.ServerAddress)
|
h.ServerAddress = gosettings.MergeWithString(h.ServerAddress, other.ServerAddress)
|
||||||
h.ReadHeaderTimeout = helpers.MergeWithNumber(h.ReadHeaderTimeout, other.ReadHeaderTimeout)
|
h.ReadHeaderTimeout = gosettings.MergeWithNumber(h.ReadHeaderTimeout, other.ReadHeaderTimeout)
|
||||||
h.ReadTimeout = helpers.MergeWithNumber(h.ReadTimeout, other.ReadTimeout)
|
h.ReadTimeout = gosettings.MergeWithNumber(h.ReadTimeout, other.ReadTimeout)
|
||||||
h.TargetAddress = helpers.MergeWithString(h.TargetAddress, other.TargetAddress)
|
h.TargetAddress = gosettings.MergeWithString(h.TargetAddress, other.TargetAddress)
|
||||||
h.SuccessWait = helpers.MergeWithNumber(h.SuccessWait, other.SuccessWait)
|
h.SuccessWait = gosettings.MergeWithNumber(h.SuccessWait, other.SuccessWait)
|
||||||
h.VPN.mergeWith(other.VPN)
|
h.VPN.mergeWith(other.VPN)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,23 +77,23 @@ func (h *Health) MergeWith(other Health) {
|
|||||||
// settings object with any field set in the other
|
// settings object with any field set in the other
|
||||||
// settings.
|
// settings.
|
||||||
func (h *Health) OverrideWith(other Health) {
|
func (h *Health) OverrideWith(other Health) {
|
||||||
h.ServerAddress = helpers.OverrideWithString(h.ServerAddress, other.ServerAddress)
|
h.ServerAddress = gosettings.OverrideWithString(h.ServerAddress, other.ServerAddress)
|
||||||
h.ReadHeaderTimeout = helpers.OverrideWithNumber(h.ReadHeaderTimeout, other.ReadHeaderTimeout)
|
h.ReadHeaderTimeout = gosettings.OverrideWithNumber(h.ReadHeaderTimeout, other.ReadHeaderTimeout)
|
||||||
h.ReadTimeout = helpers.OverrideWithNumber(h.ReadTimeout, other.ReadTimeout)
|
h.ReadTimeout = gosettings.OverrideWithNumber(h.ReadTimeout, other.ReadTimeout)
|
||||||
h.TargetAddress = helpers.OverrideWithString(h.TargetAddress, other.TargetAddress)
|
h.TargetAddress = gosettings.OverrideWithString(h.TargetAddress, other.TargetAddress)
|
||||||
h.SuccessWait = helpers.OverrideWithNumber(h.SuccessWait, other.SuccessWait)
|
h.SuccessWait = gosettings.OverrideWithNumber(h.SuccessWait, other.SuccessWait)
|
||||||
h.VPN.overrideWith(other.VPN)
|
h.VPN.overrideWith(other.VPN)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Health) SetDefaults() {
|
func (h *Health) SetDefaults() {
|
||||||
h.ServerAddress = helpers.DefaultString(h.ServerAddress, "127.0.0.1:9999")
|
h.ServerAddress = gosettings.DefaultString(h.ServerAddress, "127.0.0.1:9999")
|
||||||
const defaultReadHeaderTimeout = 100 * time.Millisecond
|
const defaultReadHeaderTimeout = 100 * time.Millisecond
|
||||||
h.ReadHeaderTimeout = helpers.DefaultNumber(h.ReadHeaderTimeout, defaultReadHeaderTimeout)
|
h.ReadHeaderTimeout = gosettings.DefaultNumber(h.ReadHeaderTimeout, defaultReadHeaderTimeout)
|
||||||
const defaultReadTimeout = 500 * time.Millisecond
|
const defaultReadTimeout = 500 * time.Millisecond
|
||||||
h.ReadTimeout = helpers.DefaultNumber(h.ReadTimeout, defaultReadTimeout)
|
h.ReadTimeout = gosettings.DefaultNumber(h.ReadTimeout, defaultReadTimeout)
|
||||||
h.TargetAddress = helpers.DefaultString(h.TargetAddress, "cloudflare.com:443")
|
h.TargetAddress = gosettings.DefaultString(h.TargetAddress, "cloudflare.com:443")
|
||||||
const defaultSuccessWait = 5 * time.Second
|
const defaultSuccessWait = 5 * time.Second
|
||||||
h.SuccessWait = helpers.DefaultNumber(h.SuccessWait, defaultSuccessWait)
|
h.SuccessWait = gosettings.DefaultNumber(h.SuccessWait, defaultSuccessWait)
|
||||||
h.VPN.setDefaults()
|
h.VPN.setDefaults()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package settings
|
|||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/configuration/settings/helpers"
|
"github.com/qdm12/gosettings"
|
||||||
"github.com/qdm12/gotree"
|
"github.com/qdm12/gotree"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -27,31 +27,31 @@ func (h HealthyWait) validate() (err error) {
|
|||||||
// unset field of the receiver settings object.
|
// unset field of the receiver settings object.
|
||||||
func (h *HealthyWait) copy() (copied HealthyWait) {
|
func (h *HealthyWait) copy() (copied HealthyWait) {
|
||||||
return HealthyWait{
|
return HealthyWait{
|
||||||
Initial: helpers.CopyPointer(h.Initial),
|
Initial: gosettings.CopyPointer(h.Initial),
|
||||||
Addition: helpers.CopyPointer(h.Addition),
|
Addition: gosettings.CopyPointer(h.Addition),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// mergeWith merges the other settings into any
|
// mergeWith merges the other settings into any
|
||||||
// unset field of the receiver settings object.
|
// unset field of the receiver settings object.
|
||||||
func (h *HealthyWait) mergeWith(other HealthyWait) {
|
func (h *HealthyWait) mergeWith(other HealthyWait) {
|
||||||
h.Initial = helpers.MergeWithPointer(h.Initial, other.Initial)
|
h.Initial = gosettings.MergeWithPointer(h.Initial, other.Initial)
|
||||||
h.Addition = helpers.MergeWithPointer(h.Addition, other.Addition)
|
h.Addition = gosettings.MergeWithPointer(h.Addition, other.Addition)
|
||||||
}
|
}
|
||||||
|
|
||||||
// overrideWith overrides fields of the receiver
|
// overrideWith overrides fields of the receiver
|
||||||
// settings object with any field set in the other
|
// settings object with any field set in the other
|
||||||
// settings.
|
// settings.
|
||||||
func (h *HealthyWait) overrideWith(other HealthyWait) {
|
func (h *HealthyWait) overrideWith(other HealthyWait) {
|
||||||
h.Initial = helpers.OverrideWithPointer(h.Initial, other.Initial)
|
h.Initial = gosettings.OverrideWithPointer(h.Initial, other.Initial)
|
||||||
h.Addition = helpers.OverrideWithPointer(h.Addition, other.Addition)
|
h.Addition = gosettings.OverrideWithPointer(h.Addition, other.Addition)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *HealthyWait) setDefaults() {
|
func (h *HealthyWait) setDefaults() {
|
||||||
const initialDurationDefault = 6 * time.Second
|
const initialDurationDefault = 6 * time.Second
|
||||||
const additionDurationDefault = 5 * time.Second
|
const additionDurationDefault = 5 * time.Second
|
||||||
h.Initial = helpers.DefaultPointer(h.Initial, initialDurationDefault)
|
h.Initial = gosettings.DefaultPointer(h.Initial, initialDurationDefault)
|
||||||
h.Addition = helpers.DefaultPointer(h.Addition, additionDurationDefault)
|
h.Addition = gosettings.DefaultPointer(h.Addition, additionDurationDefault)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h HealthyWait) String() string {
|
func (h HealthyWait) String() string {
|
||||||
|
|||||||
@@ -1,12 +1,6 @@
|
|||||||
package helpers
|
package helpers
|
||||||
|
|
||||||
import (
|
func IsOneOf[T comparable](value T, choices ...T) (ok bool) {
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
func IsOneOf(value string, choices ...string) (ok bool) {
|
|
||||||
for _, choice := range choices {
|
for _, choice := range choices {
|
||||||
if value == choice {
|
if value == choice {
|
||||||
return true
|
return true
|
||||||
@@ -14,39 +8,3 @@ func IsOneOf(value string, choices ...string) (ok bool) {
|
|||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
|
||||||
ErrNoChoice = errors.New("one or more values is set but there is no possible value available")
|
|
||||||
ErrValueNotOneOf = errors.New("value is not one of the possible choices")
|
|
||||||
)
|
|
||||||
|
|
||||||
func AreAllOneOf(values, choices []string) (err error) {
|
|
||||||
if len(values) > 0 && len(choices) == 0 {
|
|
||||||
return fmt.Errorf("%w", ErrNoChoice)
|
|
||||||
}
|
|
||||||
|
|
||||||
set := make(map[string]struct{}, len(choices))
|
|
||||||
for _, choice := range choices {
|
|
||||||
choice = strings.ToLower(choice)
|
|
||||||
set[choice] = struct{}{}
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, value := range values {
|
|
||||||
_, ok := set[value]
|
|
||||||
if !ok {
|
|
||||||
return fmt.Errorf("%w: value %q, choices available are %s",
|
|
||||||
ErrValueNotOneOf, value, strings.Join(choices, ", "))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func Uint16IsOneOf(port uint16, choices []uint16) (ok bool) {
|
|
||||||
for _, choice := range choices {
|
|
||||||
if port == choice {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ func DefaultNumber[T Number](existing T, defaultValue T) ( //nolint:ireturn
|
|||||||
return defaultValue
|
return defaultValue
|
||||||
}
|
}
|
||||||
|
|
||||||
func DefaultIP(existing netip.Addr, defaultValue netip.Addr) (
|
func DefaultValidator(existing netip.Addr, defaultValue netip.Addr) (
|
||||||
result netip.Addr) {
|
result netip.Addr) {
|
||||||
if existing.IsValid() {
|
if existing.IsValid() {
|
||||||
return existing
|
return existing
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ func MergeWithNumber[T Number](existing, other T) (result T) { //nolint:ireturn
|
|||||||
return other
|
return other
|
||||||
}
|
}
|
||||||
|
|
||||||
func MergeWithIP(existing, other netip.Addr) (result netip.Addr) {
|
func MergeWithValidator(existing, other netip.Addr) (result netip.Addr) {
|
||||||
if existing.IsValid() {
|
if existing.IsValid() {
|
||||||
return existing
|
return existing
|
||||||
}
|
}
|
||||||
@@ -44,7 +44,7 @@ func MergeWithHTTPHandler(existing, other http.Handler) (result http.Handler) {
|
|||||||
return other
|
return other
|
||||||
}
|
}
|
||||||
|
|
||||||
func MergeSlices[T comparable](a, b []T) (result []T) {
|
func MergeWithSlice[T comparable](a, b []T) (result []T) {
|
||||||
if a == nil && b == nil {
|
if a == nil && b == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ func OverrideWithNumber[T Number](existing, other T) (result T) { //nolint:iretu
|
|||||||
return other
|
return other
|
||||||
}
|
}
|
||||||
|
|
||||||
func OverrideWithIP(existing, other netip.Addr) (result netip.Addr) {
|
func OverrideWithValidator(existing, other netip.Addr) (result netip.Addr) {
|
||||||
if !other.IsValid() {
|
if !other.IsValid() {
|
||||||
return existing
|
return existing
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/configuration/settings/helpers"
|
"github.com/qdm12/gluetun/internal/configuration/settings/helpers"
|
||||||
|
"github.com/qdm12/gosettings"
|
||||||
"github.com/qdm12/gotree"
|
"github.com/qdm12/gotree"
|
||||||
"github.com/qdm12/govalid/address"
|
"github.com/qdm12/govalid/address"
|
||||||
)
|
)
|
||||||
@@ -56,12 +57,12 @@ func (h HTTPProxy) validate() (err error) {
|
|||||||
|
|
||||||
func (h *HTTPProxy) copy() (copied HTTPProxy) {
|
func (h *HTTPProxy) copy() (copied HTTPProxy) {
|
||||||
return HTTPProxy{
|
return HTTPProxy{
|
||||||
User: helpers.CopyPointer(h.User),
|
User: gosettings.CopyPointer(h.User),
|
||||||
Password: helpers.CopyPointer(h.Password),
|
Password: gosettings.CopyPointer(h.Password),
|
||||||
ListeningAddress: h.ListeningAddress,
|
ListeningAddress: h.ListeningAddress,
|
||||||
Enabled: helpers.CopyPointer(h.Enabled),
|
Enabled: gosettings.CopyPointer(h.Enabled),
|
||||||
Stealth: helpers.CopyPointer(h.Stealth),
|
Stealth: gosettings.CopyPointer(h.Stealth),
|
||||||
Log: helpers.CopyPointer(h.Log),
|
Log: gosettings.CopyPointer(h.Log),
|
||||||
ReadHeaderTimeout: h.ReadHeaderTimeout,
|
ReadHeaderTimeout: h.ReadHeaderTimeout,
|
||||||
ReadTimeout: h.ReadTimeout,
|
ReadTimeout: h.ReadTimeout,
|
||||||
}
|
}
|
||||||
@@ -70,41 +71,41 @@ func (h *HTTPProxy) copy() (copied HTTPProxy) {
|
|||||||
// mergeWith merges the other settings into any
|
// mergeWith merges the other settings into any
|
||||||
// unset field of the receiver settings object.
|
// unset field of the receiver settings object.
|
||||||
func (h *HTTPProxy) mergeWith(other HTTPProxy) {
|
func (h *HTTPProxy) mergeWith(other HTTPProxy) {
|
||||||
h.User = helpers.MergeWithPointer(h.User, other.User)
|
h.User = gosettings.MergeWithPointer(h.User, other.User)
|
||||||
h.Password = helpers.MergeWithPointer(h.Password, other.Password)
|
h.Password = gosettings.MergeWithPointer(h.Password, other.Password)
|
||||||
h.ListeningAddress = helpers.MergeWithString(h.ListeningAddress, other.ListeningAddress)
|
h.ListeningAddress = gosettings.MergeWithString(h.ListeningAddress, other.ListeningAddress)
|
||||||
h.Enabled = helpers.MergeWithPointer(h.Enabled, other.Enabled)
|
h.Enabled = gosettings.MergeWithPointer(h.Enabled, other.Enabled)
|
||||||
h.Stealth = helpers.MergeWithPointer(h.Stealth, other.Stealth)
|
h.Stealth = gosettings.MergeWithPointer(h.Stealth, other.Stealth)
|
||||||
h.Log = helpers.MergeWithPointer(h.Log, other.Log)
|
h.Log = gosettings.MergeWithPointer(h.Log, other.Log)
|
||||||
h.ReadHeaderTimeout = helpers.MergeWithNumber(h.ReadHeaderTimeout, other.ReadHeaderTimeout)
|
h.ReadHeaderTimeout = gosettings.MergeWithNumber(h.ReadHeaderTimeout, other.ReadHeaderTimeout)
|
||||||
h.ReadTimeout = helpers.MergeWithNumber(h.ReadTimeout, other.ReadTimeout)
|
h.ReadTimeout = gosettings.MergeWithNumber(h.ReadTimeout, other.ReadTimeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
// overrideWith overrides fields of the receiver
|
// overrideWith overrides fields of the receiver
|
||||||
// settings object with any field set in the other
|
// settings object with any field set in the other
|
||||||
// settings.
|
// settings.
|
||||||
func (h *HTTPProxy) overrideWith(other HTTPProxy) {
|
func (h *HTTPProxy) overrideWith(other HTTPProxy) {
|
||||||
h.User = helpers.OverrideWithPointer(h.User, other.User)
|
h.User = gosettings.OverrideWithPointer(h.User, other.User)
|
||||||
h.Password = helpers.OverrideWithPointer(h.Password, other.Password)
|
h.Password = gosettings.OverrideWithPointer(h.Password, other.Password)
|
||||||
h.ListeningAddress = helpers.OverrideWithString(h.ListeningAddress, other.ListeningAddress)
|
h.ListeningAddress = gosettings.OverrideWithString(h.ListeningAddress, other.ListeningAddress)
|
||||||
h.Enabled = helpers.OverrideWithPointer(h.Enabled, other.Enabled)
|
h.Enabled = gosettings.OverrideWithPointer(h.Enabled, other.Enabled)
|
||||||
h.Stealth = helpers.OverrideWithPointer(h.Stealth, other.Stealth)
|
h.Stealth = gosettings.OverrideWithPointer(h.Stealth, other.Stealth)
|
||||||
h.Log = helpers.OverrideWithPointer(h.Log, other.Log)
|
h.Log = gosettings.OverrideWithPointer(h.Log, other.Log)
|
||||||
h.ReadHeaderTimeout = helpers.OverrideWithNumber(h.ReadHeaderTimeout, other.ReadHeaderTimeout)
|
h.ReadHeaderTimeout = gosettings.OverrideWithNumber(h.ReadHeaderTimeout, other.ReadHeaderTimeout)
|
||||||
h.ReadTimeout = helpers.OverrideWithNumber(h.ReadTimeout, other.ReadTimeout)
|
h.ReadTimeout = gosettings.OverrideWithNumber(h.ReadTimeout, other.ReadTimeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *HTTPProxy) setDefaults() {
|
func (h *HTTPProxy) setDefaults() {
|
||||||
h.User = helpers.DefaultPointer(h.User, "")
|
h.User = gosettings.DefaultPointer(h.User, "")
|
||||||
h.Password = helpers.DefaultPointer(h.Password, "")
|
h.Password = gosettings.DefaultPointer(h.Password, "")
|
||||||
h.ListeningAddress = helpers.DefaultString(h.ListeningAddress, ":8888")
|
h.ListeningAddress = gosettings.DefaultString(h.ListeningAddress, ":8888")
|
||||||
h.Enabled = helpers.DefaultPointer(h.Enabled, false)
|
h.Enabled = gosettings.DefaultPointer(h.Enabled, false)
|
||||||
h.Stealth = helpers.DefaultPointer(h.Stealth, false)
|
h.Stealth = gosettings.DefaultPointer(h.Stealth, false)
|
||||||
h.Log = helpers.DefaultPointer(h.Log, false)
|
h.Log = gosettings.DefaultPointer(h.Log, false)
|
||||||
const defaultReadHeaderTimeout = time.Second
|
const defaultReadHeaderTimeout = time.Second
|
||||||
h.ReadHeaderTimeout = helpers.DefaultNumber(h.ReadHeaderTimeout, defaultReadHeaderTimeout)
|
h.ReadHeaderTimeout = gosettings.DefaultNumber(h.ReadHeaderTimeout, defaultReadHeaderTimeout)
|
||||||
const defaultReadTimeout = 3 * time.Second
|
const defaultReadTimeout = 3 * time.Second
|
||||||
h.ReadTimeout = helpers.DefaultNumber(h.ReadTimeout, defaultReadTimeout)
|
h.ReadTimeout = gosettings.DefaultNumber(h.ReadTimeout, defaultReadTimeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h HTTPProxy) String() string {
|
func (h HTTPProxy) String() string {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package settings
|
package settings
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/qdm12/gluetun/internal/configuration/settings/helpers"
|
"github.com/qdm12/gosettings"
|
||||||
"github.com/qdm12/gotree"
|
"github.com/qdm12/gotree"
|
||||||
"github.com/qdm12/log"
|
"github.com/qdm12/log"
|
||||||
)
|
)
|
||||||
@@ -19,25 +19,25 @@ func (l Log) validate() (err error) {
|
|||||||
|
|
||||||
func (l *Log) copy() (copied Log) {
|
func (l *Log) copy() (copied Log) {
|
||||||
return Log{
|
return Log{
|
||||||
Level: helpers.CopyPointer(l.Level),
|
Level: gosettings.CopyPointer(l.Level),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// mergeWith merges the other settings into any
|
// mergeWith merges the other settings into any
|
||||||
// unset field of the receiver settings object.
|
// unset field of the receiver settings object.
|
||||||
func (l *Log) mergeWith(other Log) {
|
func (l *Log) mergeWith(other Log) {
|
||||||
l.Level = helpers.MergeWithPointer(l.Level, other.Level)
|
l.Level = gosettings.MergeWithPointer(l.Level, other.Level)
|
||||||
}
|
}
|
||||||
|
|
||||||
// overrideWith overrides fields of the receiver
|
// overrideWith overrides fields of the receiver
|
||||||
// settings object with any field set in the other
|
// settings object with any field set in the other
|
||||||
// settings.
|
// settings.
|
||||||
func (l *Log) overrideWith(other Log) {
|
func (l *Log) overrideWith(other Log) {
|
||||||
l.Level = helpers.OverrideWithPointer(l.Level, other.Level)
|
l.Level = gosettings.OverrideWithPointer(l.Level, other.Level)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *Log) setDefaults() {
|
func (l *Log) setDefaults() {
|
||||||
l.Level = helpers.DefaultPointer(l.Level, log.LevelInfo)
|
l.Level = gosettings.DefaultPointer(l.Level, log.LevelInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l Log) String() string {
|
func (l Log) String() string {
|
||||||
|
|||||||
@@ -4,13 +4,14 @@ import (
|
|||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/configuration/settings/helpers"
|
"github.com/qdm12/gluetun/internal/configuration/settings/helpers"
|
||||||
"github.com/qdm12/gluetun/internal/constants/openvpn"
|
"github.com/qdm12/gluetun/internal/constants/openvpn"
|
||||||
"github.com/qdm12/gluetun/internal/constants/providers"
|
"github.com/qdm12/gluetun/internal/constants/providers"
|
||||||
"github.com/qdm12/gluetun/internal/openvpn/extract"
|
"github.com/qdm12/gluetun/internal/openvpn/extract"
|
||||||
"github.com/qdm12/gluetun/internal/provider/privateinternetaccess/presets"
|
"github.com/qdm12/gluetun/internal/provider/privateinternetaccess/presets"
|
||||||
|
"github.com/qdm12/gosettings"
|
||||||
|
"github.com/qdm12/gosettings/validate"
|
||||||
"github.com/qdm12/gotree"
|
"github.com/qdm12/gotree"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -89,9 +90,8 @@ var ivpnAccountID = regexp.MustCompile(`^(i|ivpn)\-[a-zA-Z0-9]{4}\-[a-zA-Z0-9]{4
|
|||||||
func (o OpenVPN) validate(vpnProvider string) (err error) {
|
func (o OpenVPN) validate(vpnProvider string) (err error) {
|
||||||
// Validate version
|
// Validate version
|
||||||
validVersions := []string{openvpn.Openvpn25, openvpn.Openvpn26}
|
validVersions := []string{openvpn.Openvpn25, openvpn.Openvpn26}
|
||||||
if !helpers.IsOneOf(o.Version, validVersions...) {
|
if err = validate.IsOneOf(o.Version, validVersions...); err != nil {
|
||||||
return fmt.Errorf("%w: %q can only be one of %s",
|
return fmt.Errorf("%w: %w", ErrOpenVPNVersionIsNotValid, err)
|
||||||
ErrOpenVPNVersionIsNotValid, o.Version, strings.Join(validVersions, ", "))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
isCustom := vpnProvider == providers.Custom
|
isCustom := vpnProvider == providers.Custom
|
||||||
@@ -244,92 +244,92 @@ func validateOpenVPNEncryptedKey(vpnProvider,
|
|||||||
func (o *OpenVPN) copy() (copied OpenVPN) {
|
func (o *OpenVPN) copy() (copied OpenVPN) {
|
||||||
return OpenVPN{
|
return OpenVPN{
|
||||||
Version: o.Version,
|
Version: o.Version,
|
||||||
User: helpers.CopyPointer(o.User),
|
User: gosettings.CopyPointer(o.User),
|
||||||
Password: helpers.CopyPointer(o.Password),
|
Password: gosettings.CopyPointer(o.Password),
|
||||||
ConfFile: helpers.CopyPointer(o.ConfFile),
|
ConfFile: gosettings.CopyPointer(o.ConfFile),
|
||||||
Ciphers: helpers.CopySlice(o.Ciphers),
|
Ciphers: gosettings.CopySlice(o.Ciphers),
|
||||||
Auth: helpers.CopyPointer(o.Auth),
|
Auth: gosettings.CopyPointer(o.Auth),
|
||||||
Cert: helpers.CopyPointer(o.Cert),
|
Cert: gosettings.CopyPointer(o.Cert),
|
||||||
Key: helpers.CopyPointer(o.Key),
|
Key: gosettings.CopyPointer(o.Key),
|
||||||
EncryptedKey: helpers.CopyPointer(o.EncryptedKey),
|
EncryptedKey: gosettings.CopyPointer(o.EncryptedKey),
|
||||||
KeyPassphrase: helpers.CopyPointer(o.KeyPassphrase),
|
KeyPassphrase: gosettings.CopyPointer(o.KeyPassphrase),
|
||||||
PIAEncPreset: helpers.CopyPointer(o.PIAEncPreset),
|
PIAEncPreset: gosettings.CopyPointer(o.PIAEncPreset),
|
||||||
MSSFix: helpers.CopyPointer(o.MSSFix),
|
MSSFix: gosettings.CopyPointer(o.MSSFix),
|
||||||
Interface: o.Interface,
|
Interface: o.Interface,
|
||||||
ProcessUser: o.ProcessUser,
|
ProcessUser: o.ProcessUser,
|
||||||
Verbosity: helpers.CopyPointer(o.Verbosity),
|
Verbosity: gosettings.CopyPointer(o.Verbosity),
|
||||||
Flags: helpers.CopySlice(o.Flags),
|
Flags: gosettings.CopySlice(o.Flags),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// mergeWith merges the other settings into any
|
// mergeWith merges the other settings into any
|
||||||
// unset field of the receiver settings object.
|
// unset field of the receiver settings object.
|
||||||
func (o *OpenVPN) mergeWith(other OpenVPN) {
|
func (o *OpenVPN) mergeWith(other OpenVPN) {
|
||||||
o.Version = helpers.MergeWithString(o.Version, other.Version)
|
o.Version = gosettings.MergeWithString(o.Version, other.Version)
|
||||||
o.User = helpers.MergeWithPointer(o.User, other.User)
|
o.User = gosettings.MergeWithPointer(o.User, other.User)
|
||||||
o.Password = helpers.MergeWithPointer(o.Password, other.Password)
|
o.Password = gosettings.MergeWithPointer(o.Password, other.Password)
|
||||||
o.ConfFile = helpers.MergeWithPointer(o.ConfFile, other.ConfFile)
|
o.ConfFile = gosettings.MergeWithPointer(o.ConfFile, other.ConfFile)
|
||||||
o.Ciphers = helpers.MergeSlices(o.Ciphers, other.Ciphers)
|
o.Ciphers = gosettings.MergeWithSlice(o.Ciphers, other.Ciphers)
|
||||||
o.Auth = helpers.MergeWithPointer(o.Auth, other.Auth)
|
o.Auth = gosettings.MergeWithPointer(o.Auth, other.Auth)
|
||||||
o.Cert = helpers.MergeWithPointer(o.Cert, other.Cert)
|
o.Cert = gosettings.MergeWithPointer(o.Cert, other.Cert)
|
||||||
o.Key = helpers.MergeWithPointer(o.Key, other.Key)
|
o.Key = gosettings.MergeWithPointer(o.Key, other.Key)
|
||||||
o.EncryptedKey = helpers.MergeWithPointer(o.EncryptedKey, other.EncryptedKey)
|
o.EncryptedKey = gosettings.MergeWithPointer(o.EncryptedKey, other.EncryptedKey)
|
||||||
o.KeyPassphrase = helpers.MergeWithPointer(o.KeyPassphrase, other.KeyPassphrase)
|
o.KeyPassphrase = gosettings.MergeWithPointer(o.KeyPassphrase, other.KeyPassphrase)
|
||||||
o.PIAEncPreset = helpers.MergeWithPointer(o.PIAEncPreset, other.PIAEncPreset)
|
o.PIAEncPreset = gosettings.MergeWithPointer(o.PIAEncPreset, other.PIAEncPreset)
|
||||||
o.MSSFix = helpers.MergeWithPointer(o.MSSFix, other.MSSFix)
|
o.MSSFix = gosettings.MergeWithPointer(o.MSSFix, other.MSSFix)
|
||||||
o.Interface = helpers.MergeWithString(o.Interface, other.Interface)
|
o.Interface = gosettings.MergeWithString(o.Interface, other.Interface)
|
||||||
o.ProcessUser = helpers.MergeWithString(o.ProcessUser, other.ProcessUser)
|
o.ProcessUser = gosettings.MergeWithString(o.ProcessUser, other.ProcessUser)
|
||||||
o.Verbosity = helpers.MergeWithPointer(o.Verbosity, other.Verbosity)
|
o.Verbosity = gosettings.MergeWithPointer(o.Verbosity, other.Verbosity)
|
||||||
o.Flags = helpers.MergeSlices(o.Flags, other.Flags)
|
o.Flags = gosettings.MergeWithSlice(o.Flags, other.Flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
// overrideWith overrides fields of the receiver
|
// overrideWith overrides fields of the receiver
|
||||||
// settings object with any field set in the other
|
// settings object with any field set in the other
|
||||||
// settings.
|
// settings.
|
||||||
func (o *OpenVPN) overrideWith(other OpenVPN) {
|
func (o *OpenVPN) overrideWith(other OpenVPN) {
|
||||||
o.Version = helpers.OverrideWithString(o.Version, other.Version)
|
o.Version = gosettings.OverrideWithString(o.Version, other.Version)
|
||||||
o.User = helpers.OverrideWithPointer(o.User, other.User)
|
o.User = gosettings.OverrideWithPointer(o.User, other.User)
|
||||||
o.Password = helpers.OverrideWithPointer(o.Password, other.Password)
|
o.Password = gosettings.OverrideWithPointer(o.Password, other.Password)
|
||||||
o.ConfFile = helpers.OverrideWithPointer(o.ConfFile, other.ConfFile)
|
o.ConfFile = gosettings.OverrideWithPointer(o.ConfFile, other.ConfFile)
|
||||||
o.Ciphers = helpers.OverrideWithSlice(o.Ciphers, other.Ciphers)
|
o.Ciphers = gosettings.OverrideWithSlice(o.Ciphers, other.Ciphers)
|
||||||
o.Auth = helpers.OverrideWithPointer(o.Auth, other.Auth)
|
o.Auth = gosettings.OverrideWithPointer(o.Auth, other.Auth)
|
||||||
o.Cert = helpers.OverrideWithPointer(o.Cert, other.Cert)
|
o.Cert = gosettings.OverrideWithPointer(o.Cert, other.Cert)
|
||||||
o.Key = helpers.OverrideWithPointer(o.Key, other.Key)
|
o.Key = gosettings.OverrideWithPointer(o.Key, other.Key)
|
||||||
o.EncryptedKey = helpers.OverrideWithPointer(o.EncryptedKey, other.EncryptedKey)
|
o.EncryptedKey = gosettings.OverrideWithPointer(o.EncryptedKey, other.EncryptedKey)
|
||||||
o.KeyPassphrase = helpers.OverrideWithPointer(o.KeyPassphrase, other.KeyPassphrase)
|
o.KeyPassphrase = gosettings.OverrideWithPointer(o.KeyPassphrase, other.KeyPassphrase)
|
||||||
o.PIAEncPreset = helpers.OverrideWithPointer(o.PIAEncPreset, other.PIAEncPreset)
|
o.PIAEncPreset = gosettings.OverrideWithPointer(o.PIAEncPreset, other.PIAEncPreset)
|
||||||
o.MSSFix = helpers.OverrideWithPointer(o.MSSFix, other.MSSFix)
|
o.MSSFix = gosettings.OverrideWithPointer(o.MSSFix, other.MSSFix)
|
||||||
o.Interface = helpers.OverrideWithString(o.Interface, other.Interface)
|
o.Interface = gosettings.OverrideWithString(o.Interface, other.Interface)
|
||||||
o.ProcessUser = helpers.OverrideWithString(o.ProcessUser, other.ProcessUser)
|
o.ProcessUser = gosettings.OverrideWithString(o.ProcessUser, other.ProcessUser)
|
||||||
o.Verbosity = helpers.OverrideWithPointer(o.Verbosity, other.Verbosity)
|
o.Verbosity = gosettings.OverrideWithPointer(o.Verbosity, other.Verbosity)
|
||||||
o.Flags = helpers.OverrideWithSlice(o.Flags, other.Flags)
|
o.Flags = gosettings.OverrideWithSlice(o.Flags, other.Flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *OpenVPN) setDefaults(vpnProvider string) {
|
func (o *OpenVPN) setDefaults(vpnProvider string) {
|
||||||
o.Version = helpers.DefaultString(o.Version, openvpn.Openvpn25)
|
o.Version = gosettings.DefaultString(o.Version, openvpn.Openvpn25)
|
||||||
o.User = helpers.DefaultPointer(o.User, "")
|
o.User = gosettings.DefaultPointer(o.User, "")
|
||||||
if vpnProvider == providers.Mullvad {
|
if vpnProvider == providers.Mullvad {
|
||||||
o.Password = helpers.DefaultPointer(o.Password, "m")
|
o.Password = gosettings.DefaultPointer(o.Password, "m")
|
||||||
} else {
|
} else {
|
||||||
o.Password = helpers.DefaultPointer(o.Password, "")
|
o.Password = gosettings.DefaultPointer(o.Password, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
o.ConfFile = helpers.DefaultPointer(o.ConfFile, "")
|
o.ConfFile = gosettings.DefaultPointer(o.ConfFile, "")
|
||||||
o.Auth = helpers.DefaultPointer(o.Auth, "")
|
o.Auth = gosettings.DefaultPointer(o.Auth, "")
|
||||||
o.Cert = helpers.DefaultPointer(o.Cert, "")
|
o.Cert = gosettings.DefaultPointer(o.Cert, "")
|
||||||
o.Key = helpers.DefaultPointer(o.Key, "")
|
o.Key = gosettings.DefaultPointer(o.Key, "")
|
||||||
o.EncryptedKey = helpers.DefaultPointer(o.EncryptedKey, "")
|
o.EncryptedKey = gosettings.DefaultPointer(o.EncryptedKey, "")
|
||||||
o.KeyPassphrase = helpers.DefaultPointer(o.KeyPassphrase, "")
|
o.KeyPassphrase = gosettings.DefaultPointer(o.KeyPassphrase, "")
|
||||||
|
|
||||||
var defaultEncPreset string
|
var defaultEncPreset string
|
||||||
if vpnProvider == providers.PrivateInternetAccess {
|
if vpnProvider == providers.PrivateInternetAccess {
|
||||||
defaultEncPreset = presets.Strong
|
defaultEncPreset = presets.Strong
|
||||||
}
|
}
|
||||||
o.PIAEncPreset = helpers.DefaultPointer(o.PIAEncPreset, defaultEncPreset)
|
o.PIAEncPreset = gosettings.DefaultPointer(o.PIAEncPreset, defaultEncPreset)
|
||||||
o.MSSFix = helpers.DefaultPointer(o.MSSFix, 0)
|
o.MSSFix = gosettings.DefaultPointer(o.MSSFix, 0)
|
||||||
o.Interface = helpers.DefaultString(o.Interface, "tun0")
|
o.Interface = gosettings.DefaultString(o.Interface, "tun0")
|
||||||
o.ProcessUser = helpers.DefaultString(o.ProcessUser, "root")
|
o.ProcessUser = gosettings.DefaultString(o.ProcessUser, "root")
|
||||||
o.Verbosity = helpers.DefaultPointer(o.Verbosity, 1)
|
o.Verbosity = gosettings.DefaultPointer(o.Verbosity, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o OpenVPN) String() string {
|
func (o OpenVPN) String() string {
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import (
|
|||||||
"github.com/qdm12/gluetun/internal/configuration/settings/helpers"
|
"github.com/qdm12/gluetun/internal/configuration/settings/helpers"
|
||||||
"github.com/qdm12/gluetun/internal/constants/providers"
|
"github.com/qdm12/gluetun/internal/constants/providers"
|
||||||
"github.com/qdm12/gluetun/internal/provider/privateinternetaccess/presets"
|
"github.com/qdm12/gluetun/internal/provider/privateinternetaccess/presets"
|
||||||
|
"github.com/qdm12/gosettings"
|
||||||
|
"github.com/qdm12/gosettings/validate"
|
||||||
"github.com/qdm12/gotree"
|
"github.com/qdm12/gotree"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -99,14 +101,14 @@ func (o OpenVPNSelection) validate(vpnProvider string) (err error) {
|
|||||||
allowedUDP = []uint16{53, 80, 123, 443, 1194, 54783}
|
allowedUDP = []uint16{53, 80, 123, 443, 1194, 54783}
|
||||||
}
|
}
|
||||||
|
|
||||||
if *o.TCP && !helpers.Uint16IsOneOf(*o.CustomPort, allowedTCP) {
|
allowedPorts := allowedUDP
|
||||||
return fmt.Errorf("%w: %d for VPN service provider %s; %s",
|
if *o.TCP {
|
||||||
ErrOpenVPNCustomPortNotAllowed, o.CustomPort, vpnProvider,
|
allowedPorts = allowedTCP
|
||||||
helpers.PortChoicesOrString(allowedTCP))
|
}
|
||||||
} else if !*o.TCP && !helpers.Uint16IsOneOf(*o.CustomPort, allowedUDP) {
|
err = validate.IsOneOf(*o.CustomPort, allowedPorts...)
|
||||||
return fmt.Errorf("%w: %d for VPN service provider %s; %s",
|
if err != nil {
|
||||||
ErrOpenVPNCustomPortNotAllowed, o.CustomPort, vpnProvider,
|
return fmt.Errorf("%w: for VPN service provider %s: %w",
|
||||||
helpers.PortChoicesOrString(allowedUDP))
|
ErrOpenVPNCustomPortNotAllowed, vpnProvider, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -118,10 +120,8 @@ func (o OpenVPNSelection) validate(vpnProvider string) (err error) {
|
|||||||
presets.Normal,
|
presets.Normal,
|
||||||
presets.Strong,
|
presets.Strong,
|
||||||
}
|
}
|
||||||
if !helpers.IsOneOf(*o.PIAEncPreset, validEncryptionPresets...) {
|
if err = validate.IsOneOf(*o.PIAEncPreset, validEncryptionPresets...); err != nil {
|
||||||
return fmt.Errorf("%w: %s; valid presets are %s",
|
return fmt.Errorf("%w: %w", ErrOpenVPNEncryptionPresetNotValid, err)
|
||||||
ErrOpenVPNEncryptionPresetNotValid, *o.PIAEncPreset,
|
|
||||||
helpers.ChoicesOrString(validEncryptionPresets))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,37 +130,37 @@ func (o OpenVPNSelection) validate(vpnProvider string) (err error) {
|
|||||||
|
|
||||||
func (o *OpenVPNSelection) copy() (copied OpenVPNSelection) {
|
func (o *OpenVPNSelection) copy() (copied OpenVPNSelection) {
|
||||||
return OpenVPNSelection{
|
return OpenVPNSelection{
|
||||||
ConfFile: helpers.CopyPointer(o.ConfFile),
|
ConfFile: gosettings.CopyPointer(o.ConfFile),
|
||||||
TCP: helpers.CopyPointer(o.TCP),
|
TCP: gosettings.CopyPointer(o.TCP),
|
||||||
CustomPort: helpers.CopyPointer(o.CustomPort),
|
CustomPort: gosettings.CopyPointer(o.CustomPort),
|
||||||
PIAEncPreset: helpers.CopyPointer(o.PIAEncPreset),
|
PIAEncPreset: gosettings.CopyPointer(o.PIAEncPreset),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *OpenVPNSelection) mergeWith(other OpenVPNSelection) {
|
func (o *OpenVPNSelection) mergeWith(other OpenVPNSelection) {
|
||||||
o.ConfFile = helpers.MergeWithPointer(o.ConfFile, other.ConfFile)
|
o.ConfFile = gosettings.MergeWithPointer(o.ConfFile, other.ConfFile)
|
||||||
o.TCP = helpers.MergeWithPointer(o.TCP, other.TCP)
|
o.TCP = gosettings.MergeWithPointer(o.TCP, other.TCP)
|
||||||
o.CustomPort = helpers.MergeWithPointer(o.CustomPort, other.CustomPort)
|
o.CustomPort = gosettings.MergeWithPointer(o.CustomPort, other.CustomPort)
|
||||||
o.PIAEncPreset = helpers.MergeWithPointer(o.PIAEncPreset, other.PIAEncPreset)
|
o.PIAEncPreset = gosettings.MergeWithPointer(o.PIAEncPreset, other.PIAEncPreset)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *OpenVPNSelection) overrideWith(other OpenVPNSelection) {
|
func (o *OpenVPNSelection) overrideWith(other OpenVPNSelection) {
|
||||||
o.ConfFile = helpers.OverrideWithPointer(o.ConfFile, other.ConfFile)
|
o.ConfFile = gosettings.OverrideWithPointer(o.ConfFile, other.ConfFile)
|
||||||
o.TCP = helpers.OverrideWithPointer(o.TCP, other.TCP)
|
o.TCP = gosettings.OverrideWithPointer(o.TCP, other.TCP)
|
||||||
o.CustomPort = helpers.OverrideWithPointer(o.CustomPort, other.CustomPort)
|
o.CustomPort = gosettings.OverrideWithPointer(o.CustomPort, other.CustomPort)
|
||||||
o.PIAEncPreset = helpers.OverrideWithPointer(o.PIAEncPreset, other.PIAEncPreset)
|
o.PIAEncPreset = gosettings.OverrideWithPointer(o.PIAEncPreset, other.PIAEncPreset)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *OpenVPNSelection) setDefaults(vpnProvider string) {
|
func (o *OpenVPNSelection) setDefaults(vpnProvider string) {
|
||||||
o.ConfFile = helpers.DefaultPointer(o.ConfFile, "")
|
o.ConfFile = gosettings.DefaultPointer(o.ConfFile, "")
|
||||||
o.TCP = helpers.DefaultPointer(o.TCP, false)
|
o.TCP = gosettings.DefaultPointer(o.TCP, false)
|
||||||
o.CustomPort = helpers.DefaultPointer(o.CustomPort, 0)
|
o.CustomPort = gosettings.DefaultPointer(o.CustomPort, 0)
|
||||||
|
|
||||||
var defaultEncPreset string
|
var defaultEncPreset string
|
||||||
if vpnProvider == providers.PrivateInternetAccess {
|
if vpnProvider == providers.PrivateInternetAccess {
|
||||||
defaultEncPreset = presets.Strong
|
defaultEncPreset = presets.Strong
|
||||||
}
|
}
|
||||||
o.PIAEncPreset = helpers.DefaultPointer(o.PIAEncPreset, defaultEncPreset)
|
o.PIAEncPreset = gosettings.DefaultPointer(o.PIAEncPreset, defaultEncPreset)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o OpenVPNSelection) String() string {
|
func (o OpenVPNSelection) String() string {
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ package settings
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/configuration/settings/helpers"
|
|
||||||
"github.com/qdm12/gluetun/internal/constants/providers"
|
"github.com/qdm12/gluetun/internal/constants/providers"
|
||||||
|
"github.com/qdm12/gosettings"
|
||||||
|
"github.com/qdm12/gosettings/validate"
|
||||||
"github.com/qdm12/gotree"
|
"github.com/qdm12/gotree"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -29,9 +29,8 @@ func (p PortForwarding) validate(vpnProvider string) (err error) {
|
|||||||
|
|
||||||
// Validate Enabled
|
// Validate Enabled
|
||||||
validProviders := []string{providers.PrivateInternetAccess}
|
validProviders := []string{providers.PrivateInternetAccess}
|
||||||
if !helpers.IsOneOf(vpnProvider, validProviders...) {
|
if err = validate.IsOneOf(vpnProvider, validProviders...); err != nil {
|
||||||
return fmt.Errorf("%w: for provider %s, it is only available for %s",
|
return fmt.Errorf("%w: %w", ErrPortForwardingEnabled, err)
|
||||||
ErrPortForwardingEnabled, vpnProvider, strings.Join(validProviders, ", "))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate Filepath
|
// Validate Filepath
|
||||||
@@ -47,24 +46,24 @@ func (p PortForwarding) validate(vpnProvider string) (err error) {
|
|||||||
|
|
||||||
func (p *PortForwarding) copy() (copied PortForwarding) {
|
func (p *PortForwarding) copy() (copied PortForwarding) {
|
||||||
return PortForwarding{
|
return PortForwarding{
|
||||||
Enabled: helpers.CopyPointer(p.Enabled),
|
Enabled: gosettings.CopyPointer(p.Enabled),
|
||||||
Filepath: helpers.CopyPointer(p.Filepath),
|
Filepath: gosettings.CopyPointer(p.Filepath),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PortForwarding) mergeWith(other PortForwarding) {
|
func (p *PortForwarding) mergeWith(other PortForwarding) {
|
||||||
p.Enabled = helpers.MergeWithPointer(p.Enabled, other.Enabled)
|
p.Enabled = gosettings.MergeWithPointer(p.Enabled, other.Enabled)
|
||||||
p.Filepath = helpers.MergeWithPointer(p.Filepath, other.Filepath)
|
p.Filepath = gosettings.MergeWithPointer(p.Filepath, other.Filepath)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PortForwarding) overrideWith(other PortForwarding) {
|
func (p *PortForwarding) overrideWith(other PortForwarding) {
|
||||||
p.Enabled = helpers.OverrideWithPointer(p.Enabled, other.Enabled)
|
p.Enabled = gosettings.OverrideWithPointer(p.Enabled, other.Enabled)
|
||||||
p.Filepath = helpers.OverrideWithPointer(p.Filepath, other.Filepath)
|
p.Filepath = gosettings.OverrideWithPointer(p.Filepath, other.Filepath)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PortForwarding) setDefaults() {
|
func (p *PortForwarding) setDefaults() {
|
||||||
p.Enabled = helpers.DefaultPointer(p.Enabled, false)
|
p.Enabled = gosettings.DefaultPointer(p.Enabled, false)
|
||||||
p.Filepath = helpers.DefaultPointer(p.Filepath, "/tmp/gluetun/forwarded_port")
|
p.Filepath = gosettings.DefaultPointer(p.Filepath, "/tmp/gluetun/forwarded_port")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p PortForwarding) String() string {
|
func (p PortForwarding) String() string {
|
||||||
|
|||||||
@@ -3,9 +3,10 @@ package settings
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/configuration/settings/helpers"
|
|
||||||
"github.com/qdm12/gluetun/internal/constants/providers"
|
"github.com/qdm12/gluetun/internal/constants/providers"
|
||||||
"github.com/qdm12/gluetun/internal/constants/vpn"
|
"github.com/qdm12/gluetun/internal/constants/vpn"
|
||||||
|
"github.com/qdm12/gosettings"
|
||||||
|
"github.com/qdm12/gosettings/validate"
|
||||||
"github.com/qdm12/gotree"
|
"github.com/qdm12/gotree"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -38,9 +39,8 @@ func (p *Provider) validate(vpnType string, storage Storage) (err error) {
|
|||||||
providers.Windscribe,
|
providers.Windscribe,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !helpers.IsOneOf(*p.Name, validNames...) {
|
if err = validate.IsOneOf(*p.Name, validNames...); err != nil {
|
||||||
return fmt.Errorf("%w for Wireguard: %q can only be one of %s",
|
return fmt.Errorf("%w for Wireguard: %w", ErrVPNProviderNameNotValid, err)
|
||||||
ErrVPNProviderNameNotValid, *p.Name, helpers.ChoicesOrString(validNames))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err = p.ServerSelection.validate(*p.Name, storage)
|
err = p.ServerSelection.validate(*p.Name, storage)
|
||||||
@@ -58,26 +58,26 @@ func (p *Provider) validate(vpnType string, storage Storage) (err error) {
|
|||||||
|
|
||||||
func (p *Provider) copy() (copied Provider) {
|
func (p *Provider) copy() (copied Provider) {
|
||||||
return Provider{
|
return Provider{
|
||||||
Name: helpers.CopyPointer(p.Name),
|
Name: gosettings.CopyPointer(p.Name),
|
||||||
ServerSelection: p.ServerSelection.copy(),
|
ServerSelection: p.ServerSelection.copy(),
|
||||||
PortForwarding: p.PortForwarding.copy(),
|
PortForwarding: p.PortForwarding.copy(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Provider) mergeWith(other Provider) {
|
func (p *Provider) mergeWith(other Provider) {
|
||||||
p.Name = helpers.MergeWithPointer(p.Name, other.Name)
|
p.Name = gosettings.MergeWithPointer(p.Name, other.Name)
|
||||||
p.ServerSelection.mergeWith(other.ServerSelection)
|
p.ServerSelection.mergeWith(other.ServerSelection)
|
||||||
p.PortForwarding.mergeWith(other.PortForwarding)
|
p.PortForwarding.mergeWith(other.PortForwarding)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Provider) overrideWith(other Provider) {
|
func (p *Provider) overrideWith(other Provider) {
|
||||||
p.Name = helpers.OverrideWithPointer(p.Name, other.Name)
|
p.Name = gosettings.OverrideWithPointer(p.Name, other.Name)
|
||||||
p.ServerSelection.overrideWith(other.ServerSelection)
|
p.ServerSelection.overrideWith(other.ServerSelection)
|
||||||
p.PortForwarding.overrideWith(other.PortForwarding)
|
p.PortForwarding.overrideWith(other.PortForwarding)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Provider) setDefaults() {
|
func (p *Provider) setDefaults() {
|
||||||
p.Name = helpers.DefaultPointer(p.Name, providers.PrivateInternetAccess)
|
p.Name = gosettings.DefaultPointer(p.Name, providers.PrivateInternetAccess)
|
||||||
p.ServerSelection.setDefaults(*p.Name)
|
p.ServerSelection.setDefaults(*p.Name)
|
||||||
p.PortForwarding.setDefaults()
|
p.PortForwarding.setDefaults()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/configuration/settings/helpers"
|
"github.com/qdm12/gosettings"
|
||||||
"github.com/qdm12/gotree"
|
"github.com/qdm12/gotree"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -42,25 +42,25 @@ func (p PublicIP) validate() (err error) {
|
|||||||
|
|
||||||
func (p *PublicIP) copy() (copied PublicIP) {
|
func (p *PublicIP) copy() (copied PublicIP) {
|
||||||
return PublicIP{
|
return PublicIP{
|
||||||
Period: helpers.CopyPointer(p.Period),
|
Period: gosettings.CopyPointer(p.Period),
|
||||||
IPFilepath: helpers.CopyPointer(p.IPFilepath),
|
IPFilepath: gosettings.CopyPointer(p.IPFilepath),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PublicIP) mergeWith(other PublicIP) {
|
func (p *PublicIP) mergeWith(other PublicIP) {
|
||||||
p.Period = helpers.MergeWithPointer(p.Period, other.Period)
|
p.Period = gosettings.MergeWithPointer(p.Period, other.Period)
|
||||||
p.IPFilepath = helpers.MergeWithPointer(p.IPFilepath, other.IPFilepath)
|
p.IPFilepath = gosettings.MergeWithPointer(p.IPFilepath, other.IPFilepath)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PublicIP) overrideWith(other PublicIP) {
|
func (p *PublicIP) overrideWith(other PublicIP) {
|
||||||
p.Period = helpers.OverrideWithPointer(p.Period, other.Period)
|
p.Period = gosettings.OverrideWithPointer(p.Period, other.Period)
|
||||||
p.IPFilepath = helpers.OverrideWithPointer(p.IPFilepath, other.IPFilepath)
|
p.IPFilepath = gosettings.OverrideWithPointer(p.IPFilepath, other.IPFilepath)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PublicIP) setDefaults() {
|
func (p *PublicIP) setDefaults() {
|
||||||
const defaultPeriod = 12 * time.Hour
|
const defaultPeriod = 12 * time.Hour
|
||||||
p.Period = helpers.DefaultPointer(p.Period, defaultPeriod)
|
p.Period = gosettings.DefaultPointer(p.Period, defaultPeriod)
|
||||||
p.IPFilepath = helpers.DefaultPointer(p.IPFilepath, "/tmp/gluetun/ip")
|
p.IPFilepath = gosettings.DefaultPointer(p.IPFilepath, "/tmp/gluetun/ip")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p PublicIP) String() string {
|
func (p PublicIP) String() string {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/configuration/settings/helpers"
|
"github.com/qdm12/gluetun/internal/configuration/settings/helpers"
|
||||||
|
"github.com/qdm12/gosettings"
|
||||||
"github.com/qdm12/gotree"
|
"github.com/qdm12/gotree"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -43,29 +44,29 @@ func (c ControlServer) validate() (err error) {
|
|||||||
|
|
||||||
func (c *ControlServer) copy() (copied ControlServer) {
|
func (c *ControlServer) copy() (copied ControlServer) {
|
||||||
return ControlServer{
|
return ControlServer{
|
||||||
Address: helpers.CopyPointer(c.Address),
|
Address: gosettings.CopyPointer(c.Address),
|
||||||
Log: helpers.CopyPointer(c.Log),
|
Log: gosettings.CopyPointer(c.Log),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// mergeWith merges the other settings into any
|
// mergeWith merges the other settings into any
|
||||||
// unset field of the receiver settings object.
|
// unset field of the receiver settings object.
|
||||||
func (c *ControlServer) mergeWith(other ControlServer) {
|
func (c *ControlServer) mergeWith(other ControlServer) {
|
||||||
c.Address = helpers.MergeWithPointer(c.Address, other.Address)
|
c.Address = gosettings.MergeWithPointer(c.Address, other.Address)
|
||||||
c.Log = helpers.MergeWithPointer(c.Log, other.Log)
|
c.Log = gosettings.MergeWithPointer(c.Log, other.Log)
|
||||||
}
|
}
|
||||||
|
|
||||||
// overrideWith overrides fields of the receiver
|
// overrideWith overrides fields of the receiver
|
||||||
// settings object with any field set in the other
|
// settings object with any field set in the other
|
||||||
// settings.
|
// settings.
|
||||||
func (c *ControlServer) overrideWith(other ControlServer) {
|
func (c *ControlServer) overrideWith(other ControlServer) {
|
||||||
c.Address = helpers.OverrideWithPointer(c.Address, other.Address)
|
c.Address = gosettings.OverrideWithPointer(c.Address, other.Address)
|
||||||
c.Log = helpers.OverrideWithPointer(c.Log, other.Log)
|
c.Log = gosettings.OverrideWithPointer(c.Log, other.Log)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ControlServer) setDefaults() {
|
func (c *ControlServer) setDefaults() {
|
||||||
c.Address = helpers.DefaultPointer(c.Address, ":8000")
|
c.Address = gosettings.DefaultPointer(c.Address, ":8000")
|
||||||
c.Log = helpers.DefaultPointer(c.Log, true)
|
c.Log = gosettings.DefaultPointer(c.Log, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c ControlServer) String() string {
|
func (c ControlServer) String() string {
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ import (
|
|||||||
"github.com/qdm12/gluetun/internal/constants/providers"
|
"github.com/qdm12/gluetun/internal/constants/providers"
|
||||||
"github.com/qdm12/gluetun/internal/constants/vpn"
|
"github.com/qdm12/gluetun/internal/constants/vpn"
|
||||||
"github.com/qdm12/gluetun/internal/models"
|
"github.com/qdm12/gluetun/internal/models"
|
||||||
|
"github.com/qdm12/gosettings"
|
||||||
|
"github.com/qdm12/gosettings/validate"
|
||||||
"github.com/qdm12/gotree"
|
"github.com/qdm12/gotree"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -88,11 +90,8 @@ func (ss *ServerSelection) validate(vpnServiceProvider string,
|
|||||||
|
|
||||||
err = validateServerFilters(*ss, filterChoices)
|
err = validateServerFilters(*ss, filterChoices)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, helpers.ErrNoChoice) {
|
|
||||||
return fmt.Errorf("for VPN service provider %s: %w", vpnServiceProvider, err)
|
return fmt.Errorf("for VPN service provider %s: %w", vpnServiceProvider, err)
|
||||||
}
|
}
|
||||||
return err // already wrapped error
|
|
||||||
}
|
|
||||||
|
|
||||||
if *ss.OwnedOnly &&
|
if *ss.OwnedOnly &&
|
||||||
vpnServiceProvider != providers.Mullvad {
|
vpnServiceProvider != providers.Mullvad {
|
||||||
@@ -160,8 +159,8 @@ func getLocationFilterChoices(vpnServiceProvider string,
|
|||||||
// // Retro compatibility
|
// // Retro compatibility
|
||||||
// TODO v4 remove
|
// TODO v4 remove
|
||||||
filterChoices.Regions = append(filterChoices.Regions, validation.SurfsharkRetroLocChoices()...)
|
filterChoices.Regions = append(filterChoices.Regions, validation.SurfsharkRetroLocChoices()...)
|
||||||
if err := helpers.AreAllOneOf(ss.Regions, filterChoices.Regions); err != nil {
|
if err := validate.AreAllOneOf(ss.Regions, filterChoices.Regions); err != nil {
|
||||||
return models.FilterChoices{}, fmt.Errorf("%w: %s", ErrRegionNotValid, err)
|
return models.FilterChoices{}, fmt.Errorf("%w: %w", ErrRegionNotValid, err)
|
||||||
}
|
}
|
||||||
*ss = surfsharkRetroRegion(*ss)
|
*ss = surfsharkRetroRegion(*ss)
|
||||||
}
|
}
|
||||||
@@ -172,28 +171,28 @@ func getLocationFilterChoices(vpnServiceProvider string,
|
|||||||
// validateServerFilters validates filters against the choices given as arguments.
|
// validateServerFilters validates filters against the choices given as arguments.
|
||||||
// Set an argument to nil to pass the check for a particular filter.
|
// Set an argument to nil to pass the check for a particular filter.
|
||||||
func validateServerFilters(settings ServerSelection, filterChoices models.FilterChoices) (err error) {
|
func validateServerFilters(settings ServerSelection, filterChoices models.FilterChoices) (err error) {
|
||||||
if err := helpers.AreAllOneOf(settings.Countries, filterChoices.Countries); err != nil {
|
if err := validate.AreAllOneOf(settings.Countries, filterChoices.Countries); err != nil {
|
||||||
return fmt.Errorf("%w: %s", ErrCountryNotValid, err)
|
return fmt.Errorf("%w: %w", ErrCountryNotValid, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := helpers.AreAllOneOf(settings.Regions, filterChoices.Regions); err != nil {
|
if err := validate.AreAllOneOf(settings.Regions, filterChoices.Regions); err != nil {
|
||||||
return fmt.Errorf("%w: %s", ErrRegionNotValid, err)
|
return fmt.Errorf("%w: %w", ErrRegionNotValid, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := helpers.AreAllOneOf(settings.Cities, filterChoices.Cities); err != nil {
|
if err := validate.AreAllOneOf(settings.Cities, filterChoices.Cities); err != nil {
|
||||||
return fmt.Errorf("%w: %s", ErrCityNotValid, err)
|
return fmt.Errorf("%w: %w", ErrCityNotValid, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := helpers.AreAllOneOf(settings.ISPs, filterChoices.ISPs); err != nil {
|
if err := validate.AreAllOneOf(settings.ISPs, filterChoices.ISPs); err != nil {
|
||||||
return fmt.Errorf("%w: %s", ErrISPNotValid, err)
|
return fmt.Errorf("%w: %w", ErrISPNotValid, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := helpers.AreAllOneOf(settings.Hostnames, filterChoices.Hostnames); err != nil {
|
if err := validate.AreAllOneOf(settings.Hostnames, filterChoices.Hostnames); err != nil {
|
||||||
return fmt.Errorf("%w: %s", ErrHostnameNotValid, err)
|
return fmt.Errorf("%w: %w", ErrHostnameNotValid, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := helpers.AreAllOneOf(settings.Names, filterChoices.Names); err != nil {
|
if err := validate.AreAllOneOf(settings.Names, filterChoices.Names); err != nil {
|
||||||
return fmt.Errorf("%w: %s", ErrNameNotValid, err)
|
return fmt.Errorf("%w: %w", ErrNameNotValid, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -203,70 +202,70 @@ func (ss *ServerSelection) copy() (copied ServerSelection) {
|
|||||||
return ServerSelection{
|
return ServerSelection{
|
||||||
VPN: ss.VPN,
|
VPN: ss.VPN,
|
||||||
TargetIP: ss.TargetIP,
|
TargetIP: ss.TargetIP,
|
||||||
Countries: helpers.CopySlice(ss.Countries),
|
Countries: gosettings.CopySlice(ss.Countries),
|
||||||
Regions: helpers.CopySlice(ss.Regions),
|
Regions: gosettings.CopySlice(ss.Regions),
|
||||||
Cities: helpers.CopySlice(ss.Cities),
|
Cities: gosettings.CopySlice(ss.Cities),
|
||||||
ISPs: helpers.CopySlice(ss.ISPs),
|
ISPs: gosettings.CopySlice(ss.ISPs),
|
||||||
Hostnames: helpers.CopySlice(ss.Hostnames),
|
Hostnames: gosettings.CopySlice(ss.Hostnames),
|
||||||
Names: helpers.CopySlice(ss.Names),
|
Names: gosettings.CopySlice(ss.Names),
|
||||||
Numbers: helpers.CopySlice(ss.Numbers),
|
Numbers: gosettings.CopySlice(ss.Numbers),
|
||||||
OwnedOnly: helpers.CopyPointer(ss.OwnedOnly),
|
OwnedOnly: gosettings.CopyPointer(ss.OwnedOnly),
|
||||||
FreeOnly: helpers.CopyPointer(ss.FreeOnly),
|
FreeOnly: gosettings.CopyPointer(ss.FreeOnly),
|
||||||
PremiumOnly: helpers.CopyPointer(ss.PremiumOnly),
|
PremiumOnly: gosettings.CopyPointer(ss.PremiumOnly),
|
||||||
StreamOnly: helpers.CopyPointer(ss.StreamOnly),
|
StreamOnly: gosettings.CopyPointer(ss.StreamOnly),
|
||||||
MultiHopOnly: helpers.CopyPointer(ss.MultiHopOnly),
|
MultiHopOnly: gosettings.CopyPointer(ss.MultiHopOnly),
|
||||||
OpenVPN: ss.OpenVPN.copy(),
|
OpenVPN: ss.OpenVPN.copy(),
|
||||||
Wireguard: ss.Wireguard.copy(),
|
Wireguard: ss.Wireguard.copy(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ss *ServerSelection) mergeWith(other ServerSelection) {
|
func (ss *ServerSelection) mergeWith(other ServerSelection) {
|
||||||
ss.VPN = helpers.MergeWithString(ss.VPN, other.VPN)
|
ss.VPN = gosettings.MergeWithString(ss.VPN, other.VPN)
|
||||||
ss.TargetIP = helpers.MergeWithIP(ss.TargetIP, other.TargetIP)
|
ss.TargetIP = gosettings.MergeWithValidator(ss.TargetIP, other.TargetIP)
|
||||||
ss.Countries = helpers.MergeSlices(ss.Countries, other.Countries)
|
ss.Countries = gosettings.MergeWithSlice(ss.Countries, other.Countries)
|
||||||
ss.Regions = helpers.MergeSlices(ss.Regions, other.Regions)
|
ss.Regions = gosettings.MergeWithSlice(ss.Regions, other.Regions)
|
||||||
ss.Cities = helpers.MergeSlices(ss.Cities, other.Cities)
|
ss.Cities = gosettings.MergeWithSlice(ss.Cities, other.Cities)
|
||||||
ss.ISPs = helpers.MergeSlices(ss.ISPs, other.ISPs)
|
ss.ISPs = gosettings.MergeWithSlice(ss.ISPs, other.ISPs)
|
||||||
ss.Hostnames = helpers.MergeSlices(ss.Hostnames, other.Hostnames)
|
ss.Hostnames = gosettings.MergeWithSlice(ss.Hostnames, other.Hostnames)
|
||||||
ss.Names = helpers.MergeSlices(ss.Names, other.Names)
|
ss.Names = gosettings.MergeWithSlice(ss.Names, other.Names)
|
||||||
ss.Numbers = helpers.MergeSlices(ss.Numbers, other.Numbers)
|
ss.Numbers = gosettings.MergeWithSlice(ss.Numbers, other.Numbers)
|
||||||
ss.OwnedOnly = helpers.MergeWithPointer(ss.OwnedOnly, other.OwnedOnly)
|
ss.OwnedOnly = gosettings.MergeWithPointer(ss.OwnedOnly, other.OwnedOnly)
|
||||||
ss.FreeOnly = helpers.MergeWithPointer(ss.FreeOnly, other.FreeOnly)
|
ss.FreeOnly = gosettings.MergeWithPointer(ss.FreeOnly, other.FreeOnly)
|
||||||
ss.PremiumOnly = helpers.MergeWithPointer(ss.PremiumOnly, other.PremiumOnly)
|
ss.PremiumOnly = gosettings.MergeWithPointer(ss.PremiumOnly, other.PremiumOnly)
|
||||||
ss.StreamOnly = helpers.MergeWithPointer(ss.StreamOnly, other.StreamOnly)
|
ss.StreamOnly = gosettings.MergeWithPointer(ss.StreamOnly, other.StreamOnly)
|
||||||
ss.MultiHopOnly = helpers.MergeWithPointer(ss.MultiHopOnly, other.MultiHopOnly)
|
ss.MultiHopOnly = gosettings.MergeWithPointer(ss.MultiHopOnly, other.MultiHopOnly)
|
||||||
|
|
||||||
ss.OpenVPN.mergeWith(other.OpenVPN)
|
ss.OpenVPN.mergeWith(other.OpenVPN)
|
||||||
ss.Wireguard.mergeWith(other.Wireguard)
|
ss.Wireguard.mergeWith(other.Wireguard)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ss *ServerSelection) overrideWith(other ServerSelection) {
|
func (ss *ServerSelection) overrideWith(other ServerSelection) {
|
||||||
ss.VPN = helpers.OverrideWithString(ss.VPN, other.VPN)
|
ss.VPN = gosettings.OverrideWithString(ss.VPN, other.VPN)
|
||||||
ss.TargetIP = helpers.OverrideWithIP(ss.TargetIP, other.TargetIP)
|
ss.TargetIP = gosettings.OverrideWithValidator(ss.TargetIP, other.TargetIP)
|
||||||
ss.Countries = helpers.OverrideWithSlice(ss.Countries, other.Countries)
|
ss.Countries = gosettings.OverrideWithSlice(ss.Countries, other.Countries)
|
||||||
ss.Regions = helpers.OverrideWithSlice(ss.Regions, other.Regions)
|
ss.Regions = gosettings.OverrideWithSlice(ss.Regions, other.Regions)
|
||||||
ss.Cities = helpers.OverrideWithSlice(ss.Cities, other.Cities)
|
ss.Cities = gosettings.OverrideWithSlice(ss.Cities, other.Cities)
|
||||||
ss.ISPs = helpers.OverrideWithSlice(ss.ISPs, other.ISPs)
|
ss.ISPs = gosettings.OverrideWithSlice(ss.ISPs, other.ISPs)
|
||||||
ss.Hostnames = helpers.OverrideWithSlice(ss.Hostnames, other.Hostnames)
|
ss.Hostnames = gosettings.OverrideWithSlice(ss.Hostnames, other.Hostnames)
|
||||||
ss.Names = helpers.OverrideWithSlice(ss.Names, other.Names)
|
ss.Names = gosettings.OverrideWithSlice(ss.Names, other.Names)
|
||||||
ss.Numbers = helpers.OverrideWithSlice(ss.Numbers, other.Numbers)
|
ss.Numbers = gosettings.OverrideWithSlice(ss.Numbers, other.Numbers)
|
||||||
ss.OwnedOnly = helpers.OverrideWithPointer(ss.OwnedOnly, other.OwnedOnly)
|
ss.OwnedOnly = gosettings.OverrideWithPointer(ss.OwnedOnly, other.OwnedOnly)
|
||||||
ss.FreeOnly = helpers.OverrideWithPointer(ss.FreeOnly, other.FreeOnly)
|
ss.FreeOnly = gosettings.OverrideWithPointer(ss.FreeOnly, other.FreeOnly)
|
||||||
ss.PremiumOnly = helpers.OverrideWithPointer(ss.PremiumOnly, other.PremiumOnly)
|
ss.PremiumOnly = gosettings.OverrideWithPointer(ss.PremiumOnly, other.PremiumOnly)
|
||||||
ss.StreamOnly = helpers.OverrideWithPointer(ss.StreamOnly, other.StreamOnly)
|
ss.StreamOnly = gosettings.OverrideWithPointer(ss.StreamOnly, other.StreamOnly)
|
||||||
ss.MultiHopOnly = helpers.OverrideWithPointer(ss.MultiHopOnly, other.MultiHopOnly)
|
ss.MultiHopOnly = gosettings.OverrideWithPointer(ss.MultiHopOnly, other.MultiHopOnly)
|
||||||
ss.OpenVPN.overrideWith(other.OpenVPN)
|
ss.OpenVPN.overrideWith(other.OpenVPN)
|
||||||
ss.Wireguard.overrideWith(other.Wireguard)
|
ss.Wireguard.overrideWith(other.Wireguard)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ss *ServerSelection) setDefaults(vpnProvider string) {
|
func (ss *ServerSelection) setDefaults(vpnProvider string) {
|
||||||
ss.VPN = helpers.DefaultString(ss.VPN, vpn.OpenVPN)
|
ss.VPN = gosettings.DefaultString(ss.VPN, vpn.OpenVPN)
|
||||||
ss.TargetIP = helpers.DefaultIP(ss.TargetIP, netip.IPv4Unspecified())
|
ss.TargetIP = gosettings.DefaultValidator(ss.TargetIP, netip.IPv4Unspecified())
|
||||||
ss.OwnedOnly = helpers.DefaultPointer(ss.OwnedOnly, false)
|
ss.OwnedOnly = gosettings.DefaultPointer(ss.OwnedOnly, false)
|
||||||
ss.FreeOnly = helpers.DefaultPointer(ss.FreeOnly, false)
|
ss.FreeOnly = gosettings.DefaultPointer(ss.FreeOnly, false)
|
||||||
ss.PremiumOnly = helpers.DefaultPointer(ss.PremiumOnly, false)
|
ss.PremiumOnly = gosettings.DefaultPointer(ss.PremiumOnly, false)
|
||||||
ss.StreamOnly = helpers.DefaultPointer(ss.StreamOnly, false)
|
ss.StreamOnly = gosettings.DefaultPointer(ss.StreamOnly, false)
|
||||||
ss.MultiHopOnly = helpers.DefaultPointer(ss.MultiHopOnly, false)
|
ss.MultiHopOnly = gosettings.DefaultPointer(ss.MultiHopOnly, false)
|
||||||
ss.OpenVPN.setDefaults(vpnProvider)
|
ss.OpenVPN.setDefaults(vpnProvider)
|
||||||
ss.Wireguard.setDefaults()
|
ss.Wireguard.setDefaults()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package settings
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/qdm12/gluetun/internal/configuration/settings/helpers"
|
"github.com/qdm12/gluetun/internal/configuration/settings/helpers"
|
||||||
|
"github.com/qdm12/gosettings"
|
||||||
"github.com/qdm12/gotree"
|
"github.com/qdm12/gotree"
|
||||||
"github.com/qdm12/ss-server/pkg/tcpudp"
|
"github.com/qdm12/ss-server/pkg/tcpudp"
|
||||||
)
|
)
|
||||||
@@ -21,7 +22,7 @@ func (s Shadowsocks) validate() (err error) {
|
|||||||
|
|
||||||
func (s *Shadowsocks) copy() (copied Shadowsocks) {
|
func (s *Shadowsocks) copy() (copied Shadowsocks) {
|
||||||
return Shadowsocks{
|
return Shadowsocks{
|
||||||
Enabled: helpers.CopyPointer(s.Enabled),
|
Enabled: gosettings.CopyPointer(s.Enabled),
|
||||||
Settings: s.Settings.Copy(),
|
Settings: s.Settings.Copy(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -29,7 +30,7 @@ func (s *Shadowsocks) copy() (copied Shadowsocks) {
|
|||||||
// mergeWith merges the other settings into any
|
// mergeWith merges the other settings into any
|
||||||
// unset field of the receiver settings object.
|
// unset field of the receiver settings object.
|
||||||
func (s *Shadowsocks) mergeWith(other Shadowsocks) {
|
func (s *Shadowsocks) mergeWith(other Shadowsocks) {
|
||||||
s.Enabled = helpers.MergeWithPointer(s.Enabled, other.Enabled)
|
s.Enabled = gosettings.MergeWithPointer(s.Enabled, other.Enabled)
|
||||||
s.Settings.MergeWith(other.Settings)
|
s.Settings.MergeWith(other.Settings)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,12 +38,12 @@ func (s *Shadowsocks) mergeWith(other Shadowsocks) {
|
|||||||
// settings object with any field set in the other
|
// settings object with any field set in the other
|
||||||
// settings.
|
// settings.
|
||||||
func (s *Shadowsocks) overrideWith(other Shadowsocks) {
|
func (s *Shadowsocks) overrideWith(other Shadowsocks) {
|
||||||
s.Enabled = helpers.OverrideWithPointer(s.Enabled, other.Enabled)
|
s.Enabled = gosettings.OverrideWithPointer(s.Enabled, other.Enabled)
|
||||||
s.Settings.OverrideWith(other.Settings)
|
s.Settings.OverrideWith(other.Settings)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Shadowsocks) setDefaults() {
|
func (s *Shadowsocks) setDefaults() {
|
||||||
s.Enabled = helpers.DefaultPointer(s.Enabled, false)
|
s.Enabled = gosettings.DefaultPointer(s.Enabled, false)
|
||||||
s.Settings.SetDefaults()
|
s.Settings.SetDefaults()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package settings
|
package settings
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/qdm12/gluetun/internal/configuration/settings/helpers"
|
"github.com/qdm12/gosettings"
|
||||||
"github.com/qdm12/gotree"
|
"github.com/qdm12/gotree"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -19,28 +19,28 @@ func (s System) validate() (err error) {
|
|||||||
|
|
||||||
func (s *System) copy() (copied System) {
|
func (s *System) copy() (copied System) {
|
||||||
return System{
|
return System{
|
||||||
PUID: helpers.CopyPointer(s.PUID),
|
PUID: gosettings.CopyPointer(s.PUID),
|
||||||
PGID: helpers.CopyPointer(s.PGID),
|
PGID: gosettings.CopyPointer(s.PGID),
|
||||||
Timezone: s.Timezone,
|
Timezone: s.Timezone,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *System) mergeWith(other System) {
|
func (s *System) mergeWith(other System) {
|
||||||
s.PUID = helpers.MergeWithPointer(s.PUID, other.PUID)
|
s.PUID = gosettings.MergeWithPointer(s.PUID, other.PUID)
|
||||||
s.PGID = helpers.MergeWithPointer(s.PGID, other.PGID)
|
s.PGID = gosettings.MergeWithPointer(s.PGID, other.PGID)
|
||||||
s.Timezone = helpers.MergeWithString(s.Timezone, other.Timezone)
|
s.Timezone = gosettings.MergeWithString(s.Timezone, other.Timezone)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *System) overrideWith(other System) {
|
func (s *System) overrideWith(other System) {
|
||||||
s.PUID = helpers.OverrideWithPointer(s.PUID, other.PUID)
|
s.PUID = gosettings.OverrideWithPointer(s.PUID, other.PUID)
|
||||||
s.PGID = helpers.OverrideWithPointer(s.PGID, other.PGID)
|
s.PGID = gosettings.OverrideWithPointer(s.PGID, other.PGID)
|
||||||
s.Timezone = helpers.OverrideWithString(s.Timezone, other.Timezone)
|
s.Timezone = gosettings.OverrideWithString(s.Timezone, other.Timezone)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *System) setDefaults() {
|
func (s *System) setDefaults() {
|
||||||
const defaultID = 1000
|
const defaultID = 1000
|
||||||
s.PUID = helpers.DefaultPointer(s.PUID, defaultID)
|
s.PUID = gosettings.DefaultPointer(s.PUID, defaultID)
|
||||||
s.PGID = helpers.DefaultPointer(s.PGID, defaultID)
|
s.PGID = gosettings.DefaultPointer(s.PGID, defaultID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s System) String() string {
|
func (s System) String() string {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/qdm12/dns/pkg/provider"
|
"github.com/qdm12/dns/pkg/provider"
|
||||||
"github.com/qdm12/dns/pkg/unbound"
|
"github.com/qdm12/dns/pkg/unbound"
|
||||||
"github.com/qdm12/gluetun/internal/configuration/settings/helpers"
|
"github.com/qdm12/gluetun/internal/configuration/settings/helpers"
|
||||||
|
"github.com/qdm12/gosettings"
|
||||||
"github.com/qdm12/gotree"
|
"github.com/qdm12/gotree"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -30,17 +31,17 @@ func (u *Unbound) setDefaults() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
u.Caching = helpers.DefaultPointer(u.Caching, true)
|
u.Caching = gosettings.DefaultPointer(u.Caching, true)
|
||||||
u.IPv6 = helpers.DefaultPointer(u.IPv6, false)
|
u.IPv6 = gosettings.DefaultPointer(u.IPv6, false)
|
||||||
|
|
||||||
const defaultVerbosityLevel = 1
|
const defaultVerbosityLevel = 1
|
||||||
u.VerbosityLevel = helpers.DefaultPointer(u.VerbosityLevel, defaultVerbosityLevel)
|
u.VerbosityLevel = gosettings.DefaultPointer(u.VerbosityLevel, defaultVerbosityLevel)
|
||||||
|
|
||||||
const defaultVerbosityDetailsLevel = 0
|
const defaultVerbosityDetailsLevel = 0
|
||||||
u.VerbosityDetailsLevel = helpers.DefaultPointer(u.VerbosityDetailsLevel, defaultVerbosityDetailsLevel)
|
u.VerbosityDetailsLevel = gosettings.DefaultPointer(u.VerbosityDetailsLevel, defaultVerbosityDetailsLevel)
|
||||||
|
|
||||||
const defaultValidationLogLevel = 0
|
const defaultValidationLogLevel = 0
|
||||||
u.ValidationLogLevel = helpers.DefaultPointer(u.ValidationLogLevel, defaultValidationLogLevel)
|
u.ValidationLogLevel = gosettings.DefaultPointer(u.ValidationLogLevel, defaultValidationLogLevel)
|
||||||
|
|
||||||
if u.Allowed == nil {
|
if u.Allowed == nil {
|
||||||
u.Allowed = []netip.Prefix{
|
u.Allowed = []netip.Prefix{
|
||||||
@@ -49,7 +50,7 @@ func (u *Unbound) setDefaults() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
u.Username = helpers.DefaultString(u.Username, "root")
|
u.Username = gosettings.DefaultString(u.Username, "root")
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -94,37 +95,37 @@ func (u Unbound) validate() (err error) {
|
|||||||
|
|
||||||
func (u Unbound) copy() (copied Unbound) {
|
func (u Unbound) copy() (copied Unbound) {
|
||||||
return Unbound{
|
return Unbound{
|
||||||
Providers: helpers.CopySlice(u.Providers),
|
Providers: gosettings.CopySlice(u.Providers),
|
||||||
Caching: helpers.CopyPointer(u.Caching),
|
Caching: gosettings.CopyPointer(u.Caching),
|
||||||
IPv6: helpers.CopyPointer(u.IPv6),
|
IPv6: gosettings.CopyPointer(u.IPv6),
|
||||||
VerbosityLevel: helpers.CopyPointer(u.VerbosityLevel),
|
VerbosityLevel: gosettings.CopyPointer(u.VerbosityLevel),
|
||||||
VerbosityDetailsLevel: helpers.CopyPointer(u.VerbosityDetailsLevel),
|
VerbosityDetailsLevel: gosettings.CopyPointer(u.VerbosityDetailsLevel),
|
||||||
ValidationLogLevel: helpers.CopyPointer(u.ValidationLogLevel),
|
ValidationLogLevel: gosettings.CopyPointer(u.ValidationLogLevel),
|
||||||
Username: u.Username,
|
Username: u.Username,
|
||||||
Allowed: helpers.CopySlice(u.Allowed),
|
Allowed: gosettings.CopySlice(u.Allowed),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *Unbound) mergeWith(other Unbound) {
|
func (u *Unbound) mergeWith(other Unbound) {
|
||||||
u.Providers = helpers.MergeSlices(u.Providers, other.Providers)
|
u.Providers = gosettings.MergeWithSlice(u.Providers, other.Providers)
|
||||||
u.Caching = helpers.MergeWithPointer(u.Caching, other.Caching)
|
u.Caching = gosettings.MergeWithPointer(u.Caching, other.Caching)
|
||||||
u.IPv6 = helpers.MergeWithPointer(u.IPv6, other.IPv6)
|
u.IPv6 = gosettings.MergeWithPointer(u.IPv6, other.IPv6)
|
||||||
u.VerbosityLevel = helpers.MergeWithPointer(u.VerbosityLevel, other.VerbosityLevel)
|
u.VerbosityLevel = gosettings.MergeWithPointer(u.VerbosityLevel, other.VerbosityLevel)
|
||||||
u.VerbosityDetailsLevel = helpers.MergeWithPointer(u.VerbosityDetailsLevel, other.VerbosityDetailsLevel)
|
u.VerbosityDetailsLevel = gosettings.MergeWithPointer(u.VerbosityDetailsLevel, other.VerbosityDetailsLevel)
|
||||||
u.ValidationLogLevel = helpers.MergeWithPointer(u.ValidationLogLevel, other.ValidationLogLevel)
|
u.ValidationLogLevel = gosettings.MergeWithPointer(u.ValidationLogLevel, other.ValidationLogLevel)
|
||||||
u.Username = helpers.MergeWithString(u.Username, other.Username)
|
u.Username = gosettings.MergeWithString(u.Username, other.Username)
|
||||||
u.Allowed = helpers.MergeSlices(u.Allowed, other.Allowed)
|
u.Allowed = gosettings.MergeWithSlice(u.Allowed, other.Allowed)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *Unbound) overrideWith(other Unbound) {
|
func (u *Unbound) overrideWith(other Unbound) {
|
||||||
u.Providers = helpers.OverrideWithSlice(u.Providers, other.Providers)
|
u.Providers = gosettings.OverrideWithSlice(u.Providers, other.Providers)
|
||||||
u.Caching = helpers.OverrideWithPointer(u.Caching, other.Caching)
|
u.Caching = gosettings.OverrideWithPointer(u.Caching, other.Caching)
|
||||||
u.IPv6 = helpers.OverrideWithPointer(u.IPv6, other.IPv6)
|
u.IPv6 = gosettings.OverrideWithPointer(u.IPv6, other.IPv6)
|
||||||
u.VerbosityLevel = helpers.OverrideWithPointer(u.VerbosityLevel, other.VerbosityLevel)
|
u.VerbosityLevel = gosettings.OverrideWithPointer(u.VerbosityLevel, other.VerbosityLevel)
|
||||||
u.VerbosityDetailsLevel = helpers.OverrideWithPointer(u.VerbosityDetailsLevel, other.VerbosityDetailsLevel)
|
u.VerbosityDetailsLevel = gosettings.OverrideWithPointer(u.VerbosityDetailsLevel, other.VerbosityDetailsLevel)
|
||||||
u.ValidationLogLevel = helpers.OverrideWithPointer(u.ValidationLogLevel, other.ValidationLogLevel)
|
u.ValidationLogLevel = gosettings.OverrideWithPointer(u.ValidationLogLevel, other.ValidationLogLevel)
|
||||||
u.Username = helpers.OverrideWithString(u.Username, other.Username)
|
u.Username = gosettings.OverrideWithString(u.Username, other.Username)
|
||||||
u.Allowed = helpers.OverrideWithSlice(u.Allowed, other.Allowed)
|
u.Allowed = gosettings.OverrideWithSlice(u.Allowed, other.Allowed)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u Unbound) ToUnboundFormat() (settings unbound.Settings, err error) {
|
func (u Unbound) ToUnboundFormat() (settings unbound.Settings, err error) {
|
||||||
|
|||||||
@@ -5,8 +5,9 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/configuration/settings/helpers"
|
|
||||||
"github.com/qdm12/gluetun/internal/constants/providers"
|
"github.com/qdm12/gluetun/internal/constants/providers"
|
||||||
|
"github.com/qdm12/gosettings"
|
||||||
|
"github.com/qdm12/gosettings/validate"
|
||||||
"github.com/qdm12/gotree"
|
"github.com/qdm12/gotree"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -45,16 +46,9 @@ func (u Updater) Validate() (err error) {
|
|||||||
|
|
||||||
validProviders := providers.All()
|
validProviders := providers.All()
|
||||||
for _, provider := range u.Providers {
|
for _, provider := range u.Providers {
|
||||||
valid := false
|
err = validate.IsOneOf(provider, validProviders...)
|
||||||
for _, validProvider := range validProviders {
|
if err != nil {
|
||||||
if provider == validProvider {
|
return fmt.Errorf("%w: %w", ErrVPNProviderNameNotValid, err)
|
||||||
valid = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !valid {
|
|
||||||
return fmt.Errorf("%w: %q can only be one of %s",
|
|
||||||
ErrVPNProviderNameNotValid, provider, helpers.ChoicesOrString(validProviders))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,35 +57,35 @@ func (u Updater) Validate() (err error) {
|
|||||||
|
|
||||||
func (u *Updater) copy() (copied Updater) {
|
func (u *Updater) copy() (copied Updater) {
|
||||||
return Updater{
|
return Updater{
|
||||||
Period: helpers.CopyPointer(u.Period),
|
Period: gosettings.CopyPointer(u.Period),
|
||||||
DNSAddress: u.DNSAddress,
|
DNSAddress: u.DNSAddress,
|
||||||
MinRatio: u.MinRatio,
|
MinRatio: u.MinRatio,
|
||||||
Providers: helpers.CopySlice(u.Providers),
|
Providers: gosettings.CopySlice(u.Providers),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// mergeWith merges the other settings into any
|
// mergeWith merges the other settings into any
|
||||||
// unset field of the receiver settings object.
|
// unset field of the receiver settings object.
|
||||||
func (u *Updater) mergeWith(other Updater) {
|
func (u *Updater) mergeWith(other Updater) {
|
||||||
u.Period = helpers.MergeWithPointer(u.Period, other.Period)
|
u.Period = gosettings.MergeWithPointer(u.Period, other.Period)
|
||||||
u.DNSAddress = helpers.MergeWithString(u.DNSAddress, other.DNSAddress)
|
u.DNSAddress = gosettings.MergeWithString(u.DNSAddress, other.DNSAddress)
|
||||||
u.MinRatio = helpers.MergeWithNumber(u.MinRatio, other.MinRatio)
|
u.MinRatio = gosettings.MergeWithNumber(u.MinRatio, other.MinRatio)
|
||||||
u.Providers = helpers.MergeSlices(u.Providers, other.Providers)
|
u.Providers = gosettings.MergeWithSlice(u.Providers, other.Providers)
|
||||||
}
|
}
|
||||||
|
|
||||||
// overrideWith overrides fields of the receiver
|
// overrideWith overrides fields of the receiver
|
||||||
// settings object with any field set in the other
|
// settings object with any field set in the other
|
||||||
// settings.
|
// settings.
|
||||||
func (u *Updater) overrideWith(other Updater) {
|
func (u *Updater) overrideWith(other Updater) {
|
||||||
u.Period = helpers.OverrideWithPointer(u.Period, other.Period)
|
u.Period = gosettings.OverrideWithPointer(u.Period, other.Period)
|
||||||
u.DNSAddress = helpers.OverrideWithString(u.DNSAddress, other.DNSAddress)
|
u.DNSAddress = gosettings.OverrideWithString(u.DNSAddress, other.DNSAddress)
|
||||||
u.MinRatio = helpers.OverrideWithNumber(u.MinRatio, other.MinRatio)
|
u.MinRatio = gosettings.OverrideWithNumber(u.MinRatio, other.MinRatio)
|
||||||
u.Providers = helpers.OverrideWithSlice(u.Providers, other.Providers)
|
u.Providers = gosettings.OverrideWithSlice(u.Providers, other.Providers)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *Updater) SetDefaults(vpnProvider string) {
|
func (u *Updater) SetDefaults(vpnProvider string) {
|
||||||
u.Period = helpers.DefaultPointer(u.Period, 0)
|
u.Period = gosettings.DefaultPointer(u.Period, 0)
|
||||||
u.DNSAddress = helpers.DefaultString(u.DNSAddress, "1.1.1.1:53")
|
u.DNSAddress = gosettings.DefaultString(u.DNSAddress, "1.1.1.1:53")
|
||||||
|
|
||||||
if u.MinRatio == 0 {
|
if u.MinRatio == 0 {
|
||||||
const defaultMinRatio = 0.8
|
const defaultMinRatio = 0.8
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package settings
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/qdm12/gluetun/internal/configuration/settings/helpers"
|
"github.com/qdm12/gluetun/internal/configuration/settings/helpers"
|
||||||
|
"github.com/qdm12/gosettings"
|
||||||
"github.com/qdm12/gotree"
|
"github.com/qdm12/gotree"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -19,25 +20,25 @@ func (v Version) validate() (err error) {
|
|||||||
|
|
||||||
func (v *Version) copy() (copied Version) {
|
func (v *Version) copy() (copied Version) {
|
||||||
return Version{
|
return Version{
|
||||||
Enabled: helpers.CopyPointer(v.Enabled),
|
Enabled: gosettings.CopyPointer(v.Enabled),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// mergeWith merges the other settings into any
|
// mergeWith merges the other settings into any
|
||||||
// unset field of the receiver settings object.
|
// unset field of the receiver settings object.
|
||||||
func (v *Version) mergeWith(other Version) {
|
func (v *Version) mergeWith(other Version) {
|
||||||
v.Enabled = helpers.MergeWithPointer(v.Enabled, other.Enabled)
|
v.Enabled = gosettings.MergeWithPointer(v.Enabled, other.Enabled)
|
||||||
}
|
}
|
||||||
|
|
||||||
// overrideWith overrides fields of the receiver
|
// overrideWith overrides fields of the receiver
|
||||||
// settings object with any field set in the other
|
// settings object with any field set in the other
|
||||||
// settings.
|
// settings.
|
||||||
func (v *Version) overrideWith(other Version) {
|
func (v *Version) overrideWith(other Version) {
|
||||||
v.Enabled = helpers.OverrideWithPointer(v.Enabled, other.Enabled)
|
v.Enabled = gosettings.OverrideWithPointer(v.Enabled, other.Enabled)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *Version) setDefaults() {
|
func (v *Version) setDefaults() {
|
||||||
v.Enabled = helpers.DefaultPointer(v.Enabled, true)
|
v.Enabled = gosettings.DefaultPointer(v.Enabled, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v Version) String() string {
|
func (v Version) String() string {
|
||||||
|
|||||||
@@ -2,10 +2,10 @@ package settings
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/configuration/settings/helpers"
|
|
||||||
"github.com/qdm12/gluetun/internal/constants/vpn"
|
"github.com/qdm12/gluetun/internal/constants/vpn"
|
||||||
|
"github.com/qdm12/gosettings"
|
||||||
|
"github.com/qdm12/gosettings/validate"
|
||||||
"github.com/qdm12/gotree"
|
"github.com/qdm12/gotree"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -23,9 +23,8 @@ type VPN struct {
|
|||||||
func (v *VPN) Validate(storage Storage, ipv6Supported bool) (err error) {
|
func (v *VPN) Validate(storage Storage, ipv6Supported bool) (err error) {
|
||||||
// Validate Type
|
// Validate Type
|
||||||
validVPNTypes := []string{vpn.OpenVPN, vpn.Wireguard}
|
validVPNTypes := []string{vpn.OpenVPN, vpn.Wireguard}
|
||||||
if !helpers.IsOneOf(v.Type, validVPNTypes...) {
|
if err = validate.IsOneOf(v.Type, validVPNTypes...); err != nil {
|
||||||
return fmt.Errorf("%w: %q and can only be one of %s",
|
return fmt.Errorf("%w: %w", ErrVPNTypeNotValid, err)
|
||||||
ErrVPNTypeNotValid, v.Type, strings.Join(validVPNTypes, ", "))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err = v.Provider.validate(v.Type, storage)
|
err = v.Provider.validate(v.Type, storage)
|
||||||
@@ -58,21 +57,21 @@ func (v *VPN) Copy() (copied VPN) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (v *VPN) mergeWith(other VPN) {
|
func (v *VPN) mergeWith(other VPN) {
|
||||||
v.Type = helpers.MergeWithString(v.Type, other.Type)
|
v.Type = gosettings.MergeWithString(v.Type, other.Type)
|
||||||
v.Provider.mergeWith(other.Provider)
|
v.Provider.mergeWith(other.Provider)
|
||||||
v.OpenVPN.mergeWith(other.OpenVPN)
|
v.OpenVPN.mergeWith(other.OpenVPN)
|
||||||
v.Wireguard.mergeWith(other.Wireguard)
|
v.Wireguard.mergeWith(other.Wireguard)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *VPN) OverrideWith(other VPN) {
|
func (v *VPN) OverrideWith(other VPN) {
|
||||||
v.Type = helpers.OverrideWithString(v.Type, other.Type)
|
v.Type = gosettings.OverrideWithString(v.Type, other.Type)
|
||||||
v.Provider.overrideWith(other.Provider)
|
v.Provider.overrideWith(other.Provider)
|
||||||
v.OpenVPN.overrideWith(other.OpenVPN)
|
v.OpenVPN.overrideWith(other.OpenVPN)
|
||||||
v.Wireguard.overrideWith(other.Wireguard)
|
v.Wireguard.overrideWith(other.Wireguard)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *VPN) setDefaults() {
|
func (v *VPN) setDefaults() {
|
||||||
v.Type = helpers.DefaultString(v.Type, vpn.OpenVPN)
|
v.Type = gosettings.DefaultString(v.Type, vpn.OpenVPN)
|
||||||
v.Provider.setDefaults()
|
v.Provider.setDefaults()
|
||||||
v.OpenVPN.setDefaults(*v.Provider.Name)
|
v.OpenVPN.setDefaults(*v.Provider.Name)
|
||||||
v.Wireguard.setDefaults()
|
v.Wireguard.setDefaults()
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import (
|
|||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/configuration/settings/helpers"
|
"github.com/qdm12/gluetun/internal/configuration/settings/helpers"
|
||||||
"github.com/qdm12/gluetun/internal/constants/providers"
|
"github.com/qdm12/gluetun/internal/constants/providers"
|
||||||
|
"github.com/qdm12/gosettings"
|
||||||
|
"github.com/qdm12/gosettings/validate"
|
||||||
"github.com/qdm12/gotree"
|
"github.com/qdm12/gotree"
|
||||||
wireguarddevice "golang.zx2c4.com/wireguard/device"
|
wireguarddevice "golang.zx2c4.com/wireguard/device"
|
||||||
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
||||||
@@ -102,9 +104,8 @@ func (w Wireguard) validate(vpnProvider string, ipv6Supported bool) (err error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
validImplementations := []string{"auto", "userspace", "kernelspace"}
|
validImplementations := []string{"auto", "userspace", "kernelspace"}
|
||||||
if !helpers.IsOneOf(w.Implementation, validImplementations...) {
|
if err := validate.IsOneOf(w.Implementation, validImplementations...); err != nil {
|
||||||
return fmt.Errorf("%w: %s must be one of %s", ErrWireguardImplementationNotValid,
|
return fmt.Errorf("%w: %w", ErrWireguardImplementationNotValid, err)
|
||||||
w.Implementation, helpers.ChoicesOrString(validImplementations))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -112,9 +113,9 @@ func (w Wireguard) validate(vpnProvider string, ipv6Supported bool) (err error)
|
|||||||
|
|
||||||
func (w *Wireguard) copy() (copied Wireguard) {
|
func (w *Wireguard) copy() (copied Wireguard) {
|
||||||
return Wireguard{
|
return Wireguard{
|
||||||
PrivateKey: helpers.CopyPointer(w.PrivateKey),
|
PrivateKey: gosettings.CopyPointer(w.PrivateKey),
|
||||||
PreSharedKey: helpers.CopyPointer(w.PreSharedKey),
|
PreSharedKey: gosettings.CopyPointer(w.PreSharedKey),
|
||||||
Addresses: helpers.CopySlice(w.Addresses),
|
Addresses: gosettings.CopySlice(w.Addresses),
|
||||||
Interface: w.Interface,
|
Interface: w.Interface,
|
||||||
MTU: w.MTU,
|
MTU: w.MTU,
|
||||||
Implementation: w.Implementation,
|
Implementation: w.Implementation,
|
||||||
@@ -122,29 +123,29 @@ func (w *Wireguard) copy() (copied Wireguard) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *Wireguard) mergeWith(other Wireguard) {
|
func (w *Wireguard) mergeWith(other Wireguard) {
|
||||||
w.PrivateKey = helpers.MergeWithPointer(w.PrivateKey, other.PrivateKey)
|
w.PrivateKey = gosettings.MergeWithPointer(w.PrivateKey, other.PrivateKey)
|
||||||
w.PreSharedKey = helpers.MergeWithPointer(w.PreSharedKey, other.PreSharedKey)
|
w.PreSharedKey = gosettings.MergeWithPointer(w.PreSharedKey, other.PreSharedKey)
|
||||||
w.Addresses = helpers.MergeSlices(w.Addresses, other.Addresses)
|
w.Addresses = gosettings.MergeWithSlice(w.Addresses, other.Addresses)
|
||||||
w.Interface = helpers.MergeWithString(w.Interface, other.Interface)
|
w.Interface = gosettings.MergeWithString(w.Interface, other.Interface)
|
||||||
w.MTU = helpers.MergeWithNumber(w.MTU, other.MTU)
|
w.MTU = gosettings.MergeWithNumber(w.MTU, other.MTU)
|
||||||
w.Implementation = helpers.MergeWithString(w.Implementation, other.Implementation)
|
w.Implementation = gosettings.MergeWithString(w.Implementation, other.Implementation)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Wireguard) overrideWith(other Wireguard) {
|
func (w *Wireguard) overrideWith(other Wireguard) {
|
||||||
w.PrivateKey = helpers.OverrideWithPointer(w.PrivateKey, other.PrivateKey)
|
w.PrivateKey = gosettings.OverrideWithPointer(w.PrivateKey, other.PrivateKey)
|
||||||
w.PreSharedKey = helpers.OverrideWithPointer(w.PreSharedKey, other.PreSharedKey)
|
w.PreSharedKey = gosettings.OverrideWithPointer(w.PreSharedKey, other.PreSharedKey)
|
||||||
w.Addresses = helpers.OverrideWithSlice(w.Addresses, other.Addresses)
|
w.Addresses = gosettings.OverrideWithSlice(w.Addresses, other.Addresses)
|
||||||
w.Interface = helpers.OverrideWithString(w.Interface, other.Interface)
|
w.Interface = gosettings.OverrideWithString(w.Interface, other.Interface)
|
||||||
w.MTU = helpers.OverrideWithNumber(w.MTU, other.MTU)
|
w.MTU = gosettings.OverrideWithNumber(w.MTU, other.MTU)
|
||||||
w.Implementation = helpers.OverrideWithString(w.Implementation, other.Implementation)
|
w.Implementation = gosettings.OverrideWithString(w.Implementation, other.Implementation)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Wireguard) setDefaults() {
|
func (w *Wireguard) setDefaults() {
|
||||||
w.PrivateKey = helpers.DefaultPointer(w.PrivateKey, "")
|
w.PrivateKey = gosettings.DefaultPointer(w.PrivateKey, "")
|
||||||
w.PreSharedKey = helpers.DefaultPointer(w.PreSharedKey, "")
|
w.PreSharedKey = gosettings.DefaultPointer(w.PreSharedKey, "")
|
||||||
w.Interface = helpers.DefaultString(w.Interface, "wg0")
|
w.Interface = gosettings.DefaultString(w.Interface, "wg0")
|
||||||
w.MTU = helpers.DefaultNumber(w.MTU, wireguarddevice.DefaultMTU)
|
w.MTU = gosettings.DefaultNumber(w.MTU, wireguarddevice.DefaultMTU)
|
||||||
w.Implementation = helpers.DefaultString(w.Implementation, "auto")
|
w.Implementation = gosettings.DefaultString(w.Implementation, "auto")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w Wireguard) String() string {
|
func (w Wireguard) String() string {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/configuration/settings/helpers"
|
"github.com/qdm12/gluetun/internal/configuration/settings/helpers"
|
||||||
"github.com/qdm12/gluetun/internal/constants/providers"
|
"github.com/qdm12/gluetun/internal/constants/providers"
|
||||||
|
"github.com/qdm12/gosettings"
|
||||||
"github.com/qdm12/gotree"
|
"github.com/qdm12/gotree"
|
||||||
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
||||||
)
|
)
|
||||||
@@ -76,7 +77,7 @@ func (w WireguardSelection) validate(vpnProvider string) (err error) {
|
|||||||
allowed = []uint16{53, 80, 123, 443, 1194, 65142}
|
allowed = []uint16{53, 80, 123, 443, 1194, 65142}
|
||||||
}
|
}
|
||||||
|
|
||||||
if helpers.Uint16IsOneOf(*w.EndpointPort, allowed) {
|
if helpers.IsOneOf(*w.EndpointPort, allowed...) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
return fmt.Errorf("%w: %d for VPN service provider %s; %s",
|
return fmt.Errorf("%w: %d for VPN service provider %s; %s",
|
||||||
@@ -110,26 +111,26 @@ func (w WireguardSelection) validate(vpnProvider string) (err error) {
|
|||||||
func (w *WireguardSelection) copy() (copied WireguardSelection) {
|
func (w *WireguardSelection) copy() (copied WireguardSelection) {
|
||||||
return WireguardSelection{
|
return WireguardSelection{
|
||||||
EndpointIP: w.EndpointIP,
|
EndpointIP: w.EndpointIP,
|
||||||
EndpointPort: helpers.CopyPointer(w.EndpointPort),
|
EndpointPort: gosettings.CopyPointer(w.EndpointPort),
|
||||||
PublicKey: w.PublicKey,
|
PublicKey: w.PublicKey,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *WireguardSelection) mergeWith(other WireguardSelection) {
|
func (w *WireguardSelection) mergeWith(other WireguardSelection) {
|
||||||
w.EndpointIP = helpers.MergeWithIP(w.EndpointIP, other.EndpointIP)
|
w.EndpointIP = gosettings.MergeWithValidator(w.EndpointIP, other.EndpointIP)
|
||||||
w.EndpointPort = helpers.MergeWithPointer(w.EndpointPort, other.EndpointPort)
|
w.EndpointPort = gosettings.MergeWithPointer(w.EndpointPort, other.EndpointPort)
|
||||||
w.PublicKey = helpers.MergeWithString(w.PublicKey, other.PublicKey)
|
w.PublicKey = gosettings.MergeWithString(w.PublicKey, other.PublicKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *WireguardSelection) overrideWith(other WireguardSelection) {
|
func (w *WireguardSelection) overrideWith(other WireguardSelection) {
|
||||||
w.EndpointIP = helpers.OverrideWithIP(w.EndpointIP, other.EndpointIP)
|
w.EndpointIP = gosettings.OverrideWithValidator(w.EndpointIP, other.EndpointIP)
|
||||||
w.EndpointPort = helpers.OverrideWithPointer(w.EndpointPort, other.EndpointPort)
|
w.EndpointPort = gosettings.OverrideWithPointer(w.EndpointPort, other.EndpointPort)
|
||||||
w.PublicKey = helpers.OverrideWithString(w.PublicKey, other.PublicKey)
|
w.PublicKey = gosettings.OverrideWithString(w.PublicKey, other.PublicKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *WireguardSelection) setDefaults() {
|
func (w *WireguardSelection) setDefaults() {
|
||||||
w.EndpointIP = helpers.DefaultIP(w.EndpointIP, netip.IPv4Unspecified())
|
w.EndpointIP = gosettings.DefaultValidator(w.EndpointIP, netip.IPv4Unspecified())
|
||||||
w.EndpointPort = helpers.DefaultPointer(w.EndpointPort, 0)
|
w.EndpointPort = gosettings.DefaultPointer(w.EndpointPort, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w WireguardSelection) String() string {
|
func (w WireguardSelection) String() string {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/configuration/settings/helpers"
|
"github.com/qdm12/gosettings"
|
||||||
"github.com/qdm12/gotree"
|
"github.com/qdm12/gotree"
|
||||||
"github.com/qdm12/govalid/address"
|
"github.com/qdm12/govalid/address"
|
||||||
)
|
)
|
||||||
@@ -34,12 +34,12 @@ type Settings struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Settings) SetDefaults() {
|
func (s *Settings) SetDefaults() {
|
||||||
s.Address = helpers.DefaultString(s.Address, ":8000")
|
s.Address = gosettings.DefaultString(s.Address, ":8000")
|
||||||
const defaultReadTimeout = 3 * time.Second
|
const defaultReadTimeout = 3 * time.Second
|
||||||
s.ReadHeaderTimeout = helpers.DefaultNumber(s.ReadHeaderTimeout, defaultReadTimeout)
|
s.ReadHeaderTimeout = gosettings.DefaultNumber(s.ReadHeaderTimeout, defaultReadTimeout)
|
||||||
s.ReadTimeout = helpers.DefaultNumber(s.ReadTimeout, defaultReadTimeout)
|
s.ReadTimeout = gosettings.DefaultNumber(s.ReadTimeout, defaultReadTimeout)
|
||||||
const defaultShutdownTimeout = 3 * time.Second
|
const defaultShutdownTimeout = 3 * time.Second
|
||||||
s.ShutdownTimeout = helpers.DefaultNumber(s.ShutdownTimeout, defaultShutdownTimeout)
|
s.ShutdownTimeout = gosettings.DefaultNumber(s.ShutdownTimeout, defaultShutdownTimeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s Settings) Copy() Settings {
|
func (s Settings) Copy() Settings {
|
||||||
@@ -54,25 +54,25 @@ func (s Settings) Copy() Settings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Settings) MergeWith(other Settings) {
|
func (s *Settings) MergeWith(other Settings) {
|
||||||
s.Address = helpers.MergeWithString(s.Address, other.Address)
|
s.Address = gosettings.MergeWithString(s.Address, other.Address)
|
||||||
s.Handler = helpers.MergeWithHTTPHandler(s.Handler, other.Handler)
|
s.Handler = gosettings.MergeWithInterface(s.Handler, other.Handler)
|
||||||
if s.Logger == nil {
|
if s.Logger == nil {
|
||||||
s.Logger = other.Logger
|
s.Logger = other.Logger
|
||||||
}
|
}
|
||||||
s.ReadHeaderTimeout = helpers.MergeWithNumber(s.ReadHeaderTimeout, other.ReadHeaderTimeout)
|
s.ReadHeaderTimeout = gosettings.MergeWithNumber(s.ReadHeaderTimeout, other.ReadHeaderTimeout)
|
||||||
s.ReadTimeout = helpers.MergeWithNumber(s.ReadTimeout, other.ReadTimeout)
|
s.ReadTimeout = gosettings.MergeWithNumber(s.ReadTimeout, other.ReadTimeout)
|
||||||
s.ShutdownTimeout = helpers.MergeWithNumber(s.ShutdownTimeout, other.ShutdownTimeout)
|
s.ShutdownTimeout = gosettings.MergeWithNumber(s.ShutdownTimeout, other.ShutdownTimeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Settings) OverrideWith(other Settings) {
|
func (s *Settings) OverrideWith(other Settings) {
|
||||||
s.Address = helpers.OverrideWithString(s.Address, other.Address)
|
s.Address = gosettings.OverrideWithString(s.Address, other.Address)
|
||||||
s.Handler = helpers.OverrideWithHTTPHandler(s.Handler, other.Handler)
|
s.Handler = gosettings.OverrideWithInterface(s.Handler, other.Handler)
|
||||||
if other.Logger != nil {
|
if other.Logger != nil {
|
||||||
s.Logger = other.Logger
|
s.Logger = other.Logger
|
||||||
}
|
}
|
||||||
s.ReadHeaderTimeout = helpers.OverrideWithNumber(s.ReadHeaderTimeout, other.ReadHeaderTimeout)
|
s.ReadHeaderTimeout = gosettings.OverrideWithNumber(s.ReadHeaderTimeout, other.ReadHeaderTimeout)
|
||||||
s.ReadTimeout = helpers.OverrideWithNumber(s.ReadTimeout, other.ReadTimeout)
|
s.ReadTimeout = gosettings.OverrideWithNumber(s.ReadTimeout, other.ReadTimeout)
|
||||||
s.ShutdownTimeout = helpers.OverrideWithNumber(s.ShutdownTimeout, other.ShutdownTimeout)
|
s.ShutdownTimeout = gosettings.OverrideWithNumber(s.ShutdownTimeout, other.ShutdownTimeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/configuration/settings/helpers"
|
|
||||||
"github.com/qdm12/gluetun/internal/httpserver"
|
"github.com/qdm12/gluetun/internal/httpserver"
|
||||||
|
"github.com/qdm12/gosettings"
|
||||||
"github.com/qdm12/gotree"
|
"github.com/qdm12/gotree"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -27,16 +27,16 @@ type Settings struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Settings) SetDefaults() {
|
func (s *Settings) SetDefaults() {
|
||||||
s.Enabled = helpers.DefaultPointer(s.Enabled, false)
|
s.Enabled = gosettings.DefaultPointer(s.Enabled, false)
|
||||||
s.HTTPServer.Address = helpers.DefaultString(s.HTTPServer.Address, "localhost:6060")
|
s.HTTPServer.Address = gosettings.DefaultString(s.HTTPServer.Address, "localhost:6060")
|
||||||
const defaultReadTimeout = 5 * time.Minute // for CPU profiling
|
const defaultReadTimeout = 5 * time.Minute // for CPU profiling
|
||||||
s.HTTPServer.ReadTimeout = helpers.DefaultNumber(s.HTTPServer.ReadTimeout, defaultReadTimeout)
|
s.HTTPServer.ReadTimeout = gosettings.DefaultNumber(s.HTTPServer.ReadTimeout, defaultReadTimeout)
|
||||||
s.HTTPServer.SetDefaults()
|
s.HTTPServer.SetDefaults()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s Settings) Copy() (copied Settings) {
|
func (s Settings) Copy() (copied Settings) {
|
||||||
return Settings{
|
return Settings{
|
||||||
Enabled: helpers.CopyPointer(s.Enabled),
|
Enabled: gosettings.CopyPointer(s.Enabled),
|
||||||
BlockProfileRate: s.BlockProfileRate,
|
BlockProfileRate: s.BlockProfileRate,
|
||||||
MutexProfileRate: s.MutexProfileRate,
|
MutexProfileRate: s.MutexProfileRate,
|
||||||
HTTPServer: s.HTTPServer.Copy(),
|
HTTPServer: s.HTTPServer.Copy(),
|
||||||
@@ -44,16 +44,16 @@ func (s Settings) Copy() (copied Settings) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Settings) MergeWith(other Settings) {
|
func (s *Settings) MergeWith(other Settings) {
|
||||||
s.Enabled = helpers.MergeWithPointer(s.Enabled, other.Enabled)
|
s.Enabled = gosettings.MergeWithPointer(s.Enabled, other.Enabled)
|
||||||
s.BlockProfileRate = helpers.MergeWithPointer(s.BlockProfileRate, other.BlockProfileRate)
|
s.BlockProfileRate = gosettings.MergeWithPointer(s.BlockProfileRate, other.BlockProfileRate)
|
||||||
s.MutexProfileRate = helpers.MergeWithPointer(s.MutexProfileRate, other.MutexProfileRate)
|
s.MutexProfileRate = gosettings.MergeWithPointer(s.MutexProfileRate, other.MutexProfileRate)
|
||||||
s.HTTPServer.MergeWith(other.HTTPServer)
|
s.HTTPServer.MergeWith(other.HTTPServer)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Settings) OverrideWith(other Settings) {
|
func (s *Settings) OverrideWith(other Settings) {
|
||||||
s.Enabled = helpers.OverrideWithPointer(s.Enabled, other.Enabled)
|
s.Enabled = gosettings.OverrideWithPointer(s.Enabled, other.Enabled)
|
||||||
s.BlockProfileRate = helpers.OverrideWithPointer(s.BlockProfileRate, other.BlockProfileRate)
|
s.BlockProfileRate = gosettings.OverrideWithPointer(s.BlockProfileRate, other.BlockProfileRate)
|
||||||
s.MutexProfileRate = helpers.OverrideWithPointer(s.MutexProfileRate, other.MutexProfileRate)
|
s.MutexProfileRate = gosettings.OverrideWithPointer(s.MutexProfileRate, other.MutexProfileRate)
|
||||||
s.HTTPServer.OverrideWith(other.HTTPServer)
|
s.HTTPServer.OverrideWith(other.HTTPServer)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user