-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
54 lines (41 loc) · 1.13 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
package main
import (
"fmt"
"github.com/kontesthq/go-load-balancer/loadbalancer"
"github.com/kontesthq/go-load-balancer/server"
"log/slog"
"time"
)
func main() {
loadBalancerClient, err := loadbalancer.NewConsulClient("localhost", 5150, "KONTEST-API", loadbalancer.RoundRobin)
if err != nil {
panic(err)
}
test(loadBalancerClient)
test(loadBalancerClient)
time.Sleep(10 * time.Second)
test(loadBalancerClient)
time.Sleep(10 * time.Second)
test(loadBalancerClient)
time.Sleep(10 * time.Second)
test(loadBalancerClient)
time.Sleep(10 * time.Second)
test(loadBalancerClient)
}
func test(client *loadbalancer.ConsulClient) {
server, err := (*client).GetLoadBalancer().ChooseServer(client)
if err != nil {
slog.Error("No ConsulClient available")
return
}
if server == nil {
slog.Error("No server found")
return
}
printServer(server)
}
func printServer(serverInstance server.Server) {
//message := fmt.Sprintf("Kind: %s, ID: %s, Address: %s, Service: %s", server.Kind, server.ID, server.Address, server.Service)
message := fmt.Sprintf("Server: %v\n", server.CommonServerString(serverInstance))
slog.Info(message)
}