feat: allow disabling monitor

This commit is contained in:
HeshamTB 2024-03-28 23:25:25 +03:00
parent fcf41c3ee7
commit 489ecd65fb

View File

@ -37,6 +37,7 @@ var wgLink *hvpnnode3.WGLink
var Country countries.CountryCode
var UUID uuid.UUID
var Monitor bool = false
var httpPort int
var TLS_ENABLED bool
@ -63,7 +64,9 @@ func run(ctx *cli.Context) {
wgLink.StartedAT = time.Now().UTC()
slog.Info(fmt.Sprintf("Started at %s", wgLink.StartedAT))
slog.Info(fmt.Sprintf("Country set to %s (%s)", Country.Alpha2(), Country.String()))
hvpnnode3.StartMonitor(wgLink, *slog.Default())
if Monitor {
hvpnnode3.StartMonitor(wgLink, *slog.Default())
}
apiMux := http.NewServeMux()
apiMux.HandleFunc("GET /node", hvpnnode3.HandleGetNodeInfo(wgLink))
@ -111,7 +114,7 @@ func createCliApp() *cli.App {
app.Name = os.Args[0]
app.HideHelpCommand = true
app.Usage = "HVPN node API server"
app.Args = true
app.Args = false
author1 := cli.Author{
Name: "Hesham T. Banafa",
@ -135,6 +138,17 @@ func createCliApp() *cli.App {
}
app.Flags = append(app.Flags, &logLevel)
monitorFlag := cli.BoolFlag{
Name: "monitor",
Usage: "Enables a periodic logger with count of current active peers",
Value: true,
Action: func(ctx *cli.Context, b bool) error {
Monitor = b
return nil
},
}
app.Flags = append(app.Flags, &monitorFlag)
privateKeyFileFlag := cli.PathFlag{
Name: "private-key",
Usage: "Path to file with private key",
@ -262,6 +276,7 @@ func createCliApp() *cli.App {
app.Flags = append(app.Flags, &TLSCertKey)
app.Action = func(ctx *cli.Context) error {
err := setup(ctx)
if err != nil {