-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
33 lines (30 loc) · 858 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
package main
import (
"context"
"fmt"
"time"
"github.com/clear-street/reinforcer/example/client"
"github.com/clear-street/reinforcer/example/client/reinforced"
"github.com/clear-street/reinforcer/pkg/runner"
"github.com/slok/goresilience/retry"
"github.com/slok/goresilience/timeout"
)
func main() {
cl := client.NewClient()
f := runner.NewFactory(
timeout.NewMiddleware(timeout.Config{Timeout: 100 * time.Millisecond}),
retry.NewMiddleware(retry.Config{
Times: 10,
}),
)
rCl := reinforced.NewClient(cl, f, reinforced.WithRetryableErrorPredicate(func(s string, err error) bool {
// Always retry SayHello, don't retry any other error
return s == reinforced.ClientMethods.SayHello
}))
for i := 0; i < 100; i++ {
err := rCl.SayHello(context.Background(), "Christian")
if err != nil {
fmt.Printf("Error: %v\n", err)
}
}
}