-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
58 lines (45 loc) · 1.18 KB
/
Copy pathmain.go
File metadata and controls
58 lines (45 loc) · 1.18 KB
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
package main
import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
"sync"
)
var wg sync.WaitGroup
func main() {
reader := bufio.NewReader(os.Stdin)
fmt.Println("Entrez votre adresse ip")
text, _ := reader.ReadString('\n')
text = strings.Trim(text, " \r\n")
fmt.Println("Entrez votre port :")
port, _ := reader.ReadString('\n')
port = strings.Trim(port, " \r\n")
portNum, err := strconv.Atoi(port)
if err != nil {
fmt.Println("Entrez un port correct")
os.Exit(1)
}
fmt.Println("Entrez votre numero\n\rTips: Le numéro doit être supérieur ou égal à 1")
num, _ := reader.ReadString('\n')
num = strings.Trim(num, " \r\n")
numConv, err := strconv.Atoi(num)
if err != nil {
fmt.Println("Ceci n'est pas un nombre")
os.Exit(1)
}
n1 := newNoeud(numConv, text, portNum)
fmt.Printf("Bienvenue noeud %d\nAdresse %s:%d\nPoids %d Voulez-vous lancer l'élection? Oui(O) ou Non(N)\n", n1.numeroOrdre, n1.ad.ip, n1.ad.port, n1.moi)
choix, _ := reader.ReadString('\n')
choix = strings.Trim(choix, " \r\n")
wg.Add(1)
go n1.reception()
switch choix {
case "O":
n1.election()
default:
fmt.Println("En attente de communication avec les autres noeuds")
}
wg.Wait()
}