@@ -95,6 +95,10 @@ func ExampleClient() {
95
95
}))
96
96
97
97
options := []httprc.NewClientOption {
98
+ // By default the client will allow all URLs (which is what the option
99
+ // below is explicitly specifying). If you want to restrict what URLs
100
+ // are allowed, you can specify another whitelist.
101
+ //
98
102
// httprc.WithWhitelist(httprc.NewInsecureWhitelist()),
99
103
}
100
104
// If you would like to handle errors from asynchronous workers, you can specify a error sink.
@@ -123,28 +127,46 @@ func ExampleClient() {
123
127
defer ctrl.Shutdown (time.Second )
124
128
125
129
// Create a new resource that is synchronized every so often
130
+ //
131
+ // By default the client will attempt to fetch the resource once
132
+ // as soon as it can, and then if no other metadata is provided,
133
+ // it will fetch the resource every 15 minutes.
134
+ //
135
+ // If the resource responds with a Cache-Control/Expires header,
136
+ // the client will attempt to respect that, and will try to fetch
137
+ // the resource again based on the values obatained from the headers.
126
138
r , err := httprc.NewResource [HelloWorld](srv.URL , httprc.JSONTransformer [HelloWorld]())
127
139
if err != nil {
128
140
fmt.Println (err.Error ())
129
141
return
130
142
}
131
143
132
- // Add the resource to the controller, so that it starts fetching
144
+ // Add the resource to the controller, so that it starts fetching.
145
+ // By default, a call to `Add()` will block until the first fetch
146
+ // succeeds, via an implicit call to `r.Ready()`
147
+ // You can change this behavior if you specify the `WithWaitReady(false)`
148
+ // option.
133
149
ctrl.Add (ctx, r)
134
150
135
- {
136
- tctx , tcancel := context.WithTimeout (ctx, time.Second )
137
- defer tcancel ()
138
- if err := r.Ready (tctx); err != nil {
139
- fmt.Println (err.Error ())
140
- return
151
+ // if you specified `httprc.WithWaitReady(false)` option, the fetch will happen
152
+ // "soon", but you're not guaranteed that it will happen before the next
153
+ // call to `Lookup()`. If you want to make sure that the resource is ready,
154
+ // you can call `Ready()` like so:
155
+ /*
156
+ {
157
+ tctx, tcancel := context.WithTimeout(ctx, time.Second)
158
+ defer tcancel()
159
+ if err := r.Ready(tctx); err != nil {
160
+ fmt.Println(err.Error())
161
+ return
162
+ }
141
163
}
142
- }
164
+ */
143
165
m := r.Resource ()
144
166
fmt.Println (m.Hello )
145
167
// OUTPUT:
146
168
// world
147
169
}
148
170
```
149
- source: [ client_example_test.go] ( https://github.com/lestrrat-go/httprc/blob/v3/client_example_test.go )
171
+ source: [ client_example_test.go] ( https://github.com/lestrrat-go/httprc/blob/refs/heads/ v3/client_example_test.go )
150
172
<!-- END INCLUDE -->
0 commit comments