73 lines
1.7 KiB
Go
Raw Permalink Normal View History

2024-09-29 18:46:39 +07:00
package main
import (
"flag"
"log"
"os"
2024-10-09 20:36:51 +03:00
"path/filepath"
2024-09-29 18:46:39 +07:00
)
func ParseFlags() (string, error) {
// String that contains the configured configuration path
var configPath string
2024-10-09 20:36:51 +03:00
exe, _ := os.Executable()
defaultCfgPath := filepath.Dir(exe)
defaultCfgPath = filepath.Join(defaultCfgPath, "/config.yml")
2024-09-29 18:46:39 +07:00
// Set up a CLI flag called "-config" to allow users
// to supply the configuration file
2024-10-09 20:36:51 +03:00
flag.StringVar(&configPath, "config", defaultCfgPath, "path to config file")
2024-09-29 18:46:39 +07:00
// 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)
}
cfg := NewConfig(cfgPath)
log := NewLog()
2025-04-06 18:36:16 +02:00
log.Info("Running FlexDXCluster version 0.2")
2024-09-29 18:46:39 +07:00
log.Infof("Callsign: %s", cfg.SQLite.Callsign)
DeleteDatabase("./flex.sqlite", log)
2024-11-16 12:24:42 +07:00
// Load country.xml to get all the DXCC number
2024-10-21 23:38:16 +07:00
Countries := LoadCountryFile()
2024-11-16 12:24:42 +07:00
// Database to keep track of all spots
2024-10-22 00:32:59 +07:00
fRepo := NewFlexDXDatabase("flex.sqlite")
2024-09-29 18:46:39 +07:00
defer fRepo.db.Close()
2024-11-16 12:24:42 +07:00
// Database connection to Log4OM
2024-10-22 00:32:59 +07:00
cRepo := NewLog4OMContactsRepository(cfg.SQLite.SQLitePath)
2024-09-29 18:46:39 +07:00
defer cRepo.db.Close()
2024-10-31 11:14:35 +07:00
TCPServer := NewTCPServer(cfg.TelnetServer.Host, cfg.TelnetServer.Port)
TCPClient := NewTCPClient(TCPServer, Countries)
2024-10-24 01:16:25 +07:00
FlexClient := NewFlexClient(*fRepo, TCPServer, TCPClient.SpotChanToFlex)
2024-11-16 12:24:42 +07:00
// HTTPServer := NewHTTPServer(*cRepo, *fRepo, TCPServer, TCPClient.SpotChanToHTTPServer)
2024-09-29 18:46:39 +07:00
2024-11-16 12:24:42 +07:00
go FlexClient.StartFlexClient()
2024-09-29 18:46:39 +07:00
go TCPClient.StartClient()
go TCPServer.StartServer()
2025-04-06 18:36:16 +02:00
CheckSignal(TCPClient, TCPServer, FlexClient, fRepo, cRepo)
2024-09-29 18:46:39 +07:00
}