-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
63 lines (52 loc) · 1.06 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package main
import "net"
import "fmt"
import "bufio"
import "os"
import "time"
var T time.Duration
var PRIORITY_MAP map[string]string
func main() {
initGlobals()
priority, ok := getPriority()
if !ok {
os.Exit(1)
}
server := &Server{
priority: priority,
state: "init",
joins: make(chan net.Conn),
}
server.Start()
for {
reader := bufio.NewReader(os.Stdin)
text, _ := reader.ReadString('\n')
fmt.Printf("CMD: %s", text)
}
}
func initGlobals() {
PRIORITY_MAP = map[string]string{
"1": "localhost:8081",
"2": "localhost:8082",
"3": "localhost:8083",
"4": "localhost:8084",
"5": "localhost:8085",
"6": "localhost:8086",
"7": "localhost:8087",
}
T = 3 * time.Second
}
func getPriority() (string, bool) {
if len(os.Args) < 2 {
fmt.Println("Print help")
return "", false
}
priority := os.Args[1]
_, ok := PRIORITY_MAP[priority]
if !ok {
fmt.Println("Priority not found:", priority)
return "", false
}
fmt.Println("Launching server with priority:", priority, ". Address:", PRIORITY_MAP[priority])
return priority, true
}