Open jamesgoodhouse opened 1 year ago
There does appear to be a way to modify a request via the Decorator func, but this means needing to construct a new NS1 client for every request.
func NewNS1Client(ctx context.Context, apiKey string) *ns1.Client {
doer := ns1.Decorate(http.DefaultClient, addContextToRequest(ctx))
return ns1.NewClient(doer, ns1.SetAPIKey(apiKey))
}
func addContextToRequest(ctx context.Context) ns1.Decorator {
return func(d ns1.Doer) ns1.Doer {
return ns1.DoerFunc(func(r *http.Request) (*http.Response, error) {
r = r.WithContext(ctx)
return d.Do(r)
})
}
}
There appears to be no way to utilize contexts for requests. This makes it impossible to set effective timeouts for requests, as well as instrument any requests. To maintain backwards compatibility, I'd suggest making additional methods called
GetWithContext
orUpdateWithContext
for example.