intercom / intercom-go

Go Bindings For Intercom
https://developers.intercom.io/reference
Other
71 stars 79 forks source link

Support of context #105

Open huttarichard opened 6 years ago

huttarichard commented 6 years ago

Client library should always take context as a first argument of every function using http client or similar. Reason is simple if there is anything in way between client and intercom server it can go forever keeping whatever is using it blocked forever (not really that uncommon).

This would be expected behavior.

ctx, cancel := context.WithCancel(context.Background())
cancel()
_, err := ic.Users.Save(ctx, &user)
// err == context.Canceled  

luckily this can be solved by patching http client for now. But I suggest new release v3 supporting context as every good library does to avoid patching intercom's http client. Or to avoid new release there is an option to add postfix ...Ctx() to every method using http client.

Example:

_, err := ic.Users.SaveCtx(ctx, &user)