added flags for ifconfig interface in server startup

main
KeeganForelight 2 years ago
parent b1db201ca5
commit 12cd29ba18

Binary file not shown.

@ -1,6 +1,10 @@
package main
import (
"flag"
"log"
"os"
"fmt"
"FRMS/internal/pkg/server"
)
@ -10,19 +14,32 @@ type reactorListener interface {
GetPort() int
}
func NewReactorListener(ch chan error) reactorListener {
return server.NewReactorListener(ch)
func NewReactorListener(s string,ch chan error) (reactorListener, error) {
return server.NewReactorListener(s, ch)
}
func main() {
// lets get this bread
// all we need to do is call the reactor coordinator and thats it
flag.Usage = func() {
w := flag.CommandLine.Output()
fmt.Fprintf(w,"Usage: %s [eth*,wlan*,etc.]\n",os.Args[0])
}
flag.Parse()
if flag.NArg() != 1 {
flag.Usage()
log.Fatal("Specify ifconfig interface. See man ifconfig for further information")
}
ifconfig := string(flag.Arg(0))
ch := make(chan error)
rl := NewReactorListener(ch)
rl, err := NewReactorListener(ifconfig,ch)
if err != nil {
log.Fatal(err)
}
go rl.Start()
err := <-ch // blocking to wait for any errors and keep alive otherwise
err = <-ch // blocking to wait for any errors and keep alive otherwise
if err != nil {
//fmt.Printf("ERROR: %v\n",err)
return
log.Fatal(err)
}
}

Binary file not shown.

@ -29,9 +29,19 @@ func GetPort() (int, error) {
return system.GetPort()
}
func NewReactorListener(ch chan error) *ReactorListener {
func NewReactorListener(ifconfig string,ch chan error) (*ReactorListener, error) {
m := make(map[uint32]*ReactorManager)
return &ReactorListener{Err:ch, Reactor:m}
var ip string
var port int
var err error
if ip, err = GetIp(ifconfig); err != nil {
return &ReactorListener{}, err
}
if port, err = GetPort(); err != nil {
return &ReactorListener{}, err
}
return &ReactorListener{Ip:ip,Port:port,Err:ch, Reactor:m}, nil
}
func (r *ReactorListener) GetIp() string {
@ -48,18 +58,6 @@ func (r *ReactorListener) GetPort() int {
func (r *ReactorListener) Start() {
// start grpc server and implement reciever
if ip, err := GetIp("eth2"); err != nil {
r.Err <-err
} else {
r.Ip = ip
}
if port, err := GetPort(); err != nil {
r.Err <-err
} else {
r.Port = port
}
if err := r.Register(); err != nil {
r.Err <- err
}

Loading…
Cancel
Save