fixing build scripts
parent
ab5f21d211
commit
d0201b23f1
@ -1,72 +0,0 @@
|
||||
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, error) {
|
||||
// allows interface checking as opposed to calling directly
|
||||
return reactor.NewCoordinator(config, ch)
|
||||
}
|
||||
|
||||
func main() {
|
||||
// shutdown
|
||||
gracefulShutdown := make(chan os.Signal, 1)
|
||||
signal.Notify(gracefulShutdown, syscall.SIGINT, syscall.SIGTERM)
|
||||
|
||||
// load any stored configs
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
configPath := fmt.Sprintf("%s/.config/FRMS", home)
|
||||
configFile := "reactor"
|
||||
configExt := "yaml"
|
||||
|
||||
conf, err := config.Load(configFile, configPath, configExt)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
ch := make(chan error)
|
||||
rlc, err := NewReactorCoordinator(conf, ch) // passing conf and err
|
||||
if err != nil {
|
||||
panic(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)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue