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.
68 lines
1.2 KiB
Go
68 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
_ "net/http"
|
|
_ "net/http/pprof"
|
|
"os/signal"
|
|
"syscall"
|
|
|
|
//"flag"
|
|
//"log"
|
|
"FRMS/internal/pkg/config"
|
|
"FRMS/internal/pkg/logging"
|
|
"FRMS/internal/pkg/server"
|
|
"os"
|
|
)
|
|
|
|
type coordinator interface {
|
|
Start()
|
|
}
|
|
|
|
type Config interface {
|
|
//UpdatePort(string, int) error
|
|
Store() error
|
|
}
|
|
|
|
func NewCoordinator(ch chan error) coordinator {
|
|
return server.NewCentralCoordinator(ch)
|
|
}
|
|
|
|
func NewConfig(fname string) Config {
|
|
return config.NewConfig(fname)
|
|
}
|
|
|
|
/*
|
|
func LoadConfig(fname string) Config {
|
|
if err := config.Load(fname); err != nil {
|
|
panic(err)
|
|
}
|
|
return config.LoadConfig()
|
|
} */
|
|
|
|
func main() {
|
|
// lets get this bread
|
|
|
|
gracefulShutdown := make(chan os.Signal, 1)
|
|
signal.Notify(gracefulShutdown, syscall.SIGINT, syscall.SIGTERM)
|
|
conf := NewConfig("server")
|
|
errCh := make(chan error)
|
|
|
|
//fmt.Printf("Listening on %v\n", lport)
|
|
c := NewCoordinator(errCh)
|
|
go c.Start()
|
|
logging.Debug(logging.DStart, "CCO 01 Server started")
|
|
select {
|
|
case err := <-errCh: // blocking to wait for any errors and keep alive otherwise
|
|
panic(err)
|
|
case <-gracefulShutdown:
|
|
// Shutdown via INT
|
|
err := conf.Store()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
fmt.Println("Stored config successfully. Exiting...")
|
|
os.Exit(0)
|
|
}
|
|
}
|