From 20952252bedebbc48ef4636641cd757e20850a4a Mon Sep 17 00:00:00 2001 From: rouggy Date: Mon, 23 Sep 2024 16:24:22 +0700 Subject: [PATCH] first commit --- main.go | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 main.go diff --git a/main.go b/main.go new file mode 100644 index 0000000..7394e96 --- /dev/null +++ b/main.go @@ -0,0 +1,78 @@ +package main + +import ( + "flag" + "log" + + "git.rouggy.com/rouggy/FlexDXCluster/logger" +) + +func ParseFlags() (string, error) { + // String that contains the configured configuration path + var configPath string + + // Set up a CLI flag called "-config" to allow users + // to supply the configuration file + flag.StringVar(&configPath, "config", "./config.yml", "path to config file") + + // Actually parse the flags + flag.Parse() + + // Validate the path first + if err := ValidateConfigPath(configPath); err != nil { + return "", err + } + + // Return the configuration path + return configPath, nil +} + +func main() { + + // Generate our config based on the config supplied + // by the user in the flags + cfgPath, err := ParseFlags() + if err != nil { + log.Fatal(err) + } + + err = NewConfig(cfgPath) + if err != nil { + log.Fatal(err) + } + + log := logger.NewLog() + + log.Info("config loaded.") + log.Infof("Callsign: %s\n", Cfg.SQLite.Callsign) + + DeleteDatabase("./flex.sqlite", log) + + repo := NewFlexDXDatabase("flex.sqlite", log) + + // Create TelnetServer + TCPServer := NewTCPServer(Cfg.Telnet.Host, Cfg.Telnet.Port, log) + + // Connect to Flex Radio (ip defined in config file) + FlexClient := NewFlexClient(*repo, TCPServer, log) + go FlexClient.StartFlexClient() + + // Connect to DX Cluster + TelnetClient := TelnetClient{ + Address: Cfg.Cluster.Server, + Port: Cfg.Cluster.Port, + Login: Cfg.Cluster.Login, + MsgChan: TCPServer.MsgChan, + CmdChan: TCPServer.CmdChan, + SpotChan: FlexClient.SpotChan, + Log: log, + } + + go TelnetClient.StartClient() + + // Start TelnetServer + go TCPServer.StartServer() + + select {} + +}