22
33Policy-driven, observable resilience for Go services: retries, hedging, circuit breaking, and budgets.
44
5- [ ![ Go Reference] ( https://pkg.go.dev/badge/github.com/aponysus/recourse.svg )] ( https://pkg.go.dev/github.com/aponysus/recourse )
5+ [ ![ Go Reference] ( https://pkg.go.dev/badge/github.com/aponysus/recourse/recourse .svg )] ( https://pkg.go.dev/github.com/aponysus/recourse /recourse )
66[ ![ Go Report Card] ( https://goreportcard.com/badge/github.com/aponysus/recourse )] ( https://goreportcard.com/report/github.com/aponysus/recourse )
77[ ![ Coverage] ( https://codecov.io/gh/aponysus/recourse/branch/main/graph/badge.svg )] ( https://codecov.io/gh/aponysus/recourse )
88[ ![ License] ( https://img.shields.io/badge/License-Apache%202.0-blue.svg )] ( https://opensource.org/licenses/Apache-2.0 )
@@ -44,6 +44,9 @@ go get github.com/aponysus/recourse@latest
4444
4545## Quick start
4646
47+ For the lowest-friction path, call the facade with a stable, low-cardinality key.
48+ If you do not call ` recourse.Init ` , the first call lazily creates the default executor and uses ` policy.DefaultPolicyFor(key) ` .
49+
4750``` go
4851package main
4952
@@ -66,6 +69,46 @@ func main() {
6669}
6770```
6871
72+ For application startup, wire explicit policies into an executor and install it before the first call:
73+
74+ ``` go
75+ package main
76+
77+ import (
78+ " context"
79+ " time"
80+
81+ " github.com/aponysus/recourse/controlplane"
82+ " github.com/aponysus/recourse/policy"
83+ " github.com/aponysus/recourse/recourse"
84+ " github.com/aponysus/recourse/retry"
85+ )
86+
87+ type User struct { ID string }
88+
89+ func main () {
90+ key := policy.ParseKey (" user-service.GetUser" )
91+ policies := map [policy.PolicyKey ]policy.EffectivePolicy {
92+ key: policy.NewFromKey (key,
93+ policy.MaxAttempts (3 ),
94+ policy.ConstantBackoff (20 *time.Millisecond ),
95+ ),
96+ }
97+
98+ recourse.Init (retry.NewDefaultExecutor (
99+ retry.WithProvider (&controlplane.StaticProvider {Policies: policies}),
100+ ))
101+
102+ user , err := recourse.DoValue [User](context.Background (), key.String (), func (ctx context.Context ) (User, error ) {
103+ return User{ID: " 123" }, nil
104+ })
105+ _ = user
106+ _ = err
107+ }
108+ ```
109+
110+ Call ` recourse.Init ` only during startup, before any ` recourse.Do ` or ` recourse.DoValue ` call. If you prefer explicit dependency ownership, use ` retry.DoValue(ctx, exec, key, op) ` directly instead of the global facade.
111+
69112## Debugging
70113
71114Capture a timeline when you need to answer "what happened on each attempt":
0 commit comments