-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_retry.go
41 lines (32 loc) · 977 Bytes
/
main_retry.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
package main
import (
"fmt"
"github.com/kontesthq/go-load-balancer/loadbalancer"
"github.com/kontesthq/go-load-balancer/server"
"log/slog"
)
func main() {
loadBalancerClient, err := loadbalancer.NewConsulClientWithCustomRule("localhost", 5150, "KONTEST-API", loadbalancer.NewRetryRule(loadbalancer.NewRoundRobinRule(), 200))
if err != nil {
panic(err)
}
test(loadBalancerClient)
slog.Info("Completed!")
}
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)
}