Maintenance: improve printVersion function
- Print program versions in order given - Exit program on any error as each program is required
This commit is contained in:
@@ -148,12 +148,14 @@ func _main(ctx context.Context, buildInfo models.BuildInformation,
|
|||||||
|
|
||||||
fmt.Println(gluetunLogging.Splash(buildInfo))
|
fmt.Println(gluetunLogging.Splash(buildInfo))
|
||||||
|
|
||||||
printVersions(ctx, logger, map[string]func(ctx context.Context) (string, error){
|
if err := printVersions(ctx, logger, []printVersionElement{
|
||||||
"Alpine": alpineConf.Version,
|
{name: "Alpine", getVersion: alpineConf.Version},
|
||||||
"OpenVPN": ovpnConf.Version,
|
{name: "OpenVPN", getVersion: ovpnConf.Version},
|
||||||
"Unbound": dnsConf.Version,
|
{name: "Unbound", getVersion: dnsConf.Version},
|
||||||
"IPtables": firewallConf.Version,
|
{name: "IPtables", getVersion: firewallConf.Version},
|
||||||
})
|
}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
var allSettings configuration.Settings
|
var allSettings configuration.Settings
|
||||||
err := allSettings.Read(params.NewEnv(), os,
|
err := allSettings.Read(params.NewEnv(), os,
|
||||||
@@ -367,19 +369,26 @@ func _main(ctx context.Context, buildInfo models.BuildInformation,
|
|||||||
return shutdownOrder.Shutdown(shutdownMaxTimeout, logger)
|
return shutdownOrder.Shutdown(shutdownMaxTimeout, logger)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type printVersionElement struct {
|
||||||
|
name string
|
||||||
|
getVersion func(ctx context.Context) (version string, err error)
|
||||||
|
}
|
||||||
|
|
||||||
func printVersions(ctx context.Context, logger logging.Logger,
|
func printVersions(ctx context.Context, logger logging.Logger,
|
||||||
versionFunctions map[string]func(ctx context.Context) (string, error)) {
|
elements []printVersionElement) (err error) {
|
||||||
const timeout = 5 * time.Second
|
const timeout = 5 * time.Second
|
||||||
ctx, cancel := context.WithTimeout(ctx, timeout)
|
ctx, cancel := context.WithTimeout(ctx, timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
for name, f := range versionFunctions {
|
|
||||||
version, err := f(ctx)
|
for _, element := range elements {
|
||||||
|
version, err := element.getVersion(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error(err)
|
return err
|
||||||
} else {
|
|
||||||
logger.Info("%s version: %s", name, version)
|
|
||||||
}
|
}
|
||||||
|
logger.Info(element.name + " version: " + version)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func routeReadyEvents(ctx context.Context, done chan<- struct{}, buildInfo models.BuildInformation,
|
func routeReadyEvents(ctx context.Context, done chan<- struct{}, buildInfo models.BuildInformation,
|
||||||
|
|||||||
Reference in New Issue
Block a user