package main import ( "os" "os/signal" "time" "wolsol-agent/auth" "wolsol-agent/config" "wolsol-agent/server" "wolsol-agent/utils" "git.secnex.io/secnex/masterlog" ) func main() { cfg := config.Load() pseudonymizer := masterlog.NewPseudonymizerFromString(utils.GetStringFromEnv("MASTERLOG_PSEUDONYMIZER", "high-secure-secret")) masterlog.SetPseudonymizer(pseudonymizer) masterlog.SetLevel(masterlog.Level(utils.GetIntFromEnv("MASTERLOG_LEVEL", int(masterlog.LevelInfo)))) masterlog.AddSensitiveFields("AUTH_USER", "AUTH_PASS") masterlog.Info("Authentication enabled") authenticator := auth.New(cfg.AuthUser, cfg.AuthPass) sigChan := make(chan os.Signal, 1) // Use os.Interrupt which works on all platforms (Windows, Linux, macOS) signal.Notify(sigChan, os.Interrupt) udpServer := server.NewUDPServer(cfg.SOLPort, authenticator) udpDone := make(chan bool) go udpServer.Start(udpDone) var apiDone chan bool if cfg.APIEnabled { apiServer := server.NewAPIServer(cfg.APIPort, authenticator) apiDone = make(chan bool) go apiServer.Start(apiDone) } masterlog.Info("Starting servers", map[string]interface{}{ "SOL_PORT": cfg.SOLPort, "API_PORT": cfg.APIPort, "API_ENABLED": cfg.APIEnabled, }) <-sigChan masterlog.Info("Shutting down", map[string]interface{}{ "SOL_PORT": cfg.SOLPort, "API_PORT": cfg.APIPort, "API_ENABLED": cfg.APIEnabled, }) close(udpDone) if apiDone != nil { close(apiDone) } time.Sleep(100 * time.Millisecond) }