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.

69 lines
1.5 KiB
Go

package main
import (
"FRMS/internal/pkg/config"
"FRMS/internal/pkg/logging"
"FRMS/internal/pkg/reactor"
flag "github.com/spf13/pflag"
"github.com/spf13/viper"
)
type coordinator interface {
Start()
}
func NewCoordinator(ip string, port int, ch chan error) coordinator {
// allows interface checking as opposed to calling directly
return reactor.NewCoordinator(ip, port, ch)
}
type Config interface {
Load() error // load config, keys and env for a string
Store() error // write any pending changes
}
func NewConfig(fname string) Config {
if conf, err := config.NewConfig(fname); err != nil {
panic(err)
}
return conf
}
func main() {
// load any stored settings
conf := NewConfig("reactor") // loads .yaml and flags
conf.Load() // load exisiting settings
// get overrides
var ip string
var port int
/*
flag.Usage = func() {
w := flag.CommandLine.Output()
fmt.Fprintf(w, "Usage: %s port \n",os.Args[0])
}*/
iptr := flag.String("ip", "192.168.100.2", "server ip")
portptr := flag.String("port", 2022, "server port")
nameptr := flag.String("name", "", "human readable name")
flag.Parse()
// lets us retrieve them from viper later
if err := viper.BindPFlags(flag.CommandLine); err != nil {
panic(err)
}
ch := make(chan error)
rlc := NewCoordinator(ch) // passing only err chan
go rlc.Start()
logging.Debug(logging.DStart, "Reactor Started")
for err = range ch {
if err != nil {
panic(err)
}
}
}