writeas / go-writeas

Go client for the Write.as API
MIT License
22 stars 11 forks source link

context.Context support #11

Open abhinav opened 5 years ago

abhinav commented 5 years ago

Overview

Go client libraries typically accept a context.Context as the first argument in all outgoing function calls. The context carries deadline and other information across API boundaries. See also https://blog.golang.org/context.

Popular examples are,

Context also allows orchestrating cancelation, especially with concurrent operations. Support for this is already built into http.Client.

Implementation

All methods that make an outgoing request would have to accept a context.Context as their first argument and plumb it over to http.Client with req.WithContext(ctx), likely in buildRequest or prepareRequest.

Because this will involve a breaking change to the API, it should probably be bundled with any other breaking changes you have planned.

thebaer commented 5 years ago

Great input! If anyone wants to jump on this for the v2 release of the library, please feel free to do so now. It'll be a good time to bring in this breaking change.