update
This commit is contained in:
87
main.go
Normal file
87
main.go
Normal file
@ -0,0 +1,87 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
cfg := NewConfig(cfgPath)
|
||||
|
||||
log := NewLog()
|
||||
|
||||
log.Info("config loaded.")
|
||||
log.Infof("Callsign: %s", cfg.SQLite.Callsign)
|
||||
|
||||
DeleteDatabase("./flex.sqlite", log)
|
||||
|
||||
fRepo := NewFlexDXDatabase("flex.sqlite", log)
|
||||
defer fRepo.db.Close()
|
||||
|
||||
cRepo := NewLog4OMContactsRepository(cfg.SQLite.SQLitePath, log)
|
||||
defer cRepo.db.Close()
|
||||
|
||||
TCPServer := NewTCPServer(cfg.TelnetServer.Host, cfg.TelnetServer.Port, log)
|
||||
FlexClient := NewFlexClient(*fRepo, *TCPServer, log)
|
||||
TCPClient := NewTCPClient(TCPServer, FlexClient, log)
|
||||
HTTPServer := NewHTTPServer(*cRepo, *fRepo, *FlexClient, log)
|
||||
|
||||
sigCh := make(chan os.Signal, 1)
|
||||
signal.Notify(sigCh, syscall.SIGHUP, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM)
|
||||
|
||||
go FlexClient.StartFlexClient()
|
||||
go TCPClient.StartClient()
|
||||
go TCPServer.StartServer()
|
||||
|
||||
go HTTPServer.StartHTTPServer()
|
||||
|
||||
for sig := range sigCh {
|
||||
log.Infof("received signal: %v, shutting down TCP Client.", sig)
|
||||
|
||||
TCPClient.Close()
|
||||
|
||||
if err := fRepo.db.Close(); err != nil {
|
||||
log.Error("failed to close the database connection properly")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if err := cRepo.db.Close(); err != nil {
|
||||
log.Error("failed to close Log4OM database connection properly")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user