@@ -95,6 +95,10 @@ func ExampleClient() {
9595 }))
9696
9797 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+ //
98102 // httprc.WithWhitelist(httprc.NewInsecureWhitelist()),
99103 }
100104 // If you would like to handle errors from asynchronous workers, you can specify a error sink.
@@ -123,28 +127,46 @@ func ExampleClient() {
123127 defer ctrl.Shutdown (time.Second )
124128
125129 // 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.
126138 r , err := httprc.NewResource [HelloWorld](srv.URL , httprc.JSONTransformer [HelloWorld]())
127139 if err != nil {
128140 fmt.Println (err.Error ())
129141 return
130142 }
131143
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.
133149 ctrl.Add (ctx, r)
134150
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+ }
141163 }
142- }
164+ */
143165 m := r.Resource ()
144166 fmt.Println (m.Hello )
145167 // OUTPUT:
146168 // world
147169}
148170```
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 )
150172<!-- END INCLUDE -->
0 commit comments