FlexDXCluster/main.go

64 lines
1.3 KiB
Go
Raw Normal View History

2024-09-23 16:24:22 +07:00
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.")
2024-09-24 11:57:48 +07:00
log.Infof("Callsign: %s", Cfg.SQLite.Callsign)
2024-09-23 16:24:22 +07:00
DeleteDatabase("./flex.sqlite", log)
repo := NewFlexDXDatabase("flex.sqlite", log)
TCPServer := NewTCPServer(Cfg.Telnet.Host, Cfg.Telnet.Port, log)
2024-09-24 11:57:48 +07:00
FlexClient := NewFlexClient(*repo, *TCPServer, log)
TCPClient := NewTCPClient(*Cfg, TCPServer, FlexClient, log)
2024-09-23 16:24:22 +07:00
go FlexClient.StartFlexClient()
2024-09-24 11:57:48 +07:00
go TCPClient.StartClient()
2024-09-23 16:24:22 +07:00
go TCPServer.StartServer()
select {}
}