-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
44 lines (36 loc) · 987 Bytes
/
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
package main
import (
"fmt"
"github.com/rampa2510/system-design/commons"
"github.com/rampa2510/system-design/loadBalancingAlgo"
)
type AlgorithmFunc func()
var AlgorithmMap = map[int]struct {
Name string
Func AlgorithmFunc
}{
1: {"Simple Hashing", loadbalancingalgo.SimpleHashing},
2: {"Consistent Hashing", loadbalancingalgo.ConsistentHashing},
3: {"Weighted round robin", loadbalancingalgo.WeightedRoundRobin},
4: {"Least connection", loadbalancingalgo.LeastConnection},
}
func main() {
for {
fmt.Println("\nSelect an algorithm to run:")
for num, algo := range AlgorithmMap {
fmt.Printf("%d. %s\n", num, algo.Name)
}
var choice int
commons.AcceptInput("Enter your choice (0 to exit): ", &choice)
if choice == 0 {
fmt.Println("Exiting the program. Goodbye!")
return
}
if algo, ok := AlgorithmMap[choice]; ok {
fmt.Printf("\nRunning %s\n", algo.Name)
algo.Func()
} else {
fmt.Println("Invalid selection. Please try again.")
}
}
}