Code maintenance: Better deps injection in main.go
This commit is contained in:
@@ -41,25 +41,28 @@ import (
|
|||||||
|
|
||||||
//nolint:gochecknoglobals
|
//nolint:gochecknoglobals
|
||||||
var (
|
var (
|
||||||
buildInfo models.BuildInformation
|
|
||||||
version = "unknown"
|
version = "unknown"
|
||||||
commit = "unknown"
|
commit = "unknown"
|
||||||
buildDate = "an unknown date"
|
buildDate = "an unknown date"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
buildInfo.Version = version
|
buildInfo := models.BuildInformation{
|
||||||
buildInfo.Commit = commit
|
Version: version,
|
||||||
buildInfo.BuildDate = buildDate
|
Commit: commit,
|
||||||
|
BuildDate: buildDate,
|
||||||
|
}
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
args := nativeos.Args
|
args := nativeos.Args
|
||||||
os := os.New()
|
os := os.New()
|
||||||
osUser := user.New()
|
osUser := user.New()
|
||||||
nativeos.Exit(_main(ctx, args, os, osUser))
|
unix := unix.New()
|
||||||
|
nativeos.Exit(_main(ctx, buildInfo, args, os, osUser, unix))
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint:gocognit,gocyclo
|
//nolint:gocognit,gocyclo
|
||||||
func _main(background context.Context, args []string, os os.OS, osUser user.OSUser) int {
|
func _main(background context.Context, buildInfo models.BuildInformation,
|
||||||
|
args []string, os os.OS, osUser user.OSUser, unix unix.Unix) int {
|
||||||
if len(args) > 1 { // cli operation
|
if len(args) > 1 { // cli operation
|
||||||
var err error
|
var err error
|
||||||
switch args[1] {
|
switch args[1] {
|
||||||
@@ -89,7 +92,6 @@ func _main(background context.Context, args []string, os os.OS, osUser user.OSUs
|
|||||||
client := network.NewClient(clientTimeout)
|
client := network.NewClient(clientTimeout)
|
||||||
// Create configurators
|
// Create configurators
|
||||||
alpineConf := alpine.NewConfigurator(os.OpenFile, osUser)
|
alpineConf := alpine.NewConfigurator(os.OpenFile, osUser)
|
||||||
unix := unix.New()
|
|
||||||
ovpnConf := openvpn.NewConfigurator(logger, os, unix)
|
ovpnConf := openvpn.NewConfigurator(logger, os, unix)
|
||||||
dnsConf := dns.NewConfigurator(logger, client, os.OpenFile)
|
dnsConf := dns.NewConfigurator(logger, client, os.OpenFile)
|
||||||
routingConf := routing.NewRouting(logger)
|
routingConf := routing.NewRouting(logger)
|
||||||
@@ -274,7 +276,7 @@ func _main(background context.Context, args []string, os os.OS, osUser user.OSUs
|
|||||||
}
|
}
|
||||||
|
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go routeReadyEvents(ctx, wg, tunnelReadyCh, dnsReadyCh,
|
go routeReadyEvents(ctx, wg, buildInfo, tunnelReadyCh, dnsReadyCh,
|
||||||
unboundLooper, updaterLooper, publicIPLooper, routingConf, logger, httpClient,
|
unboundLooper, updaterLooper, publicIPLooper, routingConf, logger, httpClient,
|
||||||
allSettings.VersionInformation, allSettings.OpenVPN.Provider.PortForwarding.Enabled, openvpnLooper.PortForward,
|
allSettings.VersionInformation, allSettings.OpenVPN.Provider.PortForwarding.Enabled, openvpnLooper.PortForward,
|
||||||
)
|
)
|
||||||
@@ -395,7 +397,8 @@ func collectStreamLines(ctx context.Context, streamMerger command.StreamMerger,
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func routeReadyEvents(ctx context.Context, wg *sync.WaitGroup, tunnelReadyCh, dnsReadyCh <-chan struct{},
|
func routeReadyEvents(ctx context.Context, wg *sync.WaitGroup, buildInfo models.BuildInformation,
|
||||||
|
tunnelReadyCh, dnsReadyCh <-chan struct{},
|
||||||
unboundLooper dns.Looper, updaterLooper updater.Looper, publicIPLooper publicip.Looper,
|
unboundLooper dns.Looper, updaterLooper updater.Looper, publicIPLooper publicip.Looper,
|
||||||
routing routing.Routing, logger logging.Logger, httpClient *http.Client,
|
routing routing.Routing, logger logging.Logger, httpClient *http.Client,
|
||||||
versionInformation, portForwardingEnabled bool, startPortForward func(vpnGateway net.IP)) {
|
versionInformation, portForwardingEnabled bool, startPortForward func(vpnGateway net.IP)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user