You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.1 KiB
Go

package main
import (
"FRMS/internal/pkg/config"
"FRMS/internal/pkg/logging"
"FRMS/internal/pkg/reactor"
"fmt"
"os"
"syscall"
"os/signal"
"github.com/spf13/viper"
)
type reactorCoordinator interface {
Start()
}
func NewReactorCoordinator(config *viper.Viper, ch chan error) reactorCoordinator {
// allows interface checking as opposed to calling directly
return reactor.NewCoordinator(config, ch)
}
func NewConfig(fname string) *viper.Viper {
return config.LoadConfig(fname)
}
func main() {
// shutdown
gracefulShutdown := make(chan os.Signal, 1)
signal.Notify(gracefulShutdown, syscall.SIGINT, syscall.SIGTERM)
// load any stored configs
conf := NewConfig("reactor")
ch := make(chan error)
rlc := NewReactorCoordinator(conf, ch) // passing conf and err
go rlc.Start()
logging.Debug(logging.DStart, "Reactor Started")
// check for errors
select {
case err := <-ch:
if err != nil {
conf.WriteConfig() // save changes
panic(err)
}
case <-gracefulShutdown:
// sigint
fmt.Printf("\nStoring config to %s\n", conf.ConfigFileUsed())
if err := conf.WriteConfig(); err != nil {
panic(err)
}
os.Exit(0)
}
}