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.

60 lines
1.2 KiB
Go

package main
import (
"fmt"
"os"
"flag"
"log"
"strings"
"strconv"
2 years ago
"FRMS/internal/pkg/reactor"
)
2 years ago
type coordinator interface {
Start()
}
func NewCoordinator(ip string,port int,ch chan error) coordinator {
2 years ago
// allows interface checking as opposed to calling directly
return reactor.NewCoordinator(ip,port,ch)
2 years ago
}
2 years ago
func main() {
var ip string
var port int
flag.Usage = func() {
w := flag.CommandLine.Output()
fmt.Fprintf(w, "Usage: %s ip_addr port \n",os.Args[0])
}
flag.Parse()
if flag.NArg() != 2 {
flag.Usage()
os.Exit(1)
}
args := flag.Args()
if s := strings.Split(args[0],"."); len(s) != 4 {
flag.Usage()
log.Fatal("second arguement must be an ip address of type x.x.x.x")
}
if p, err := strconv.Atoi(args[1]);p < 1024 || p > 65535 {
flag.Usage()
log.Fatal("Port must be between [1023,65535]")
} else if err != nil {
log.Fatal(err)
}
ip = args[0]
port, err := strconv.Atoi(args[1])
if err != nil {
log.Fatal(err)
}
2 years ago
ch := make(chan error)
rlc := NewCoordinator(ip,port,ch) // host port
2 years ago
go rlc.Start()
err = <-ch
2 years ago
if err != nil {
log.Fatal(err)
}
}