Add context.Context to the func signatures in gen_*.go
liuerfire opened this issue ยท 2 comments
For backwards compatibility, maybe add extra methods like
func (bot *Bot) SendMessageWithContext(ctx context.Context, chatId int64, text string, opts *SendMessageOpts) (*Message, error)
Why need this
For example, we have a web server, then need to send messages to users if they make some actions on our website. A typical code maybe like this:
func (api *API) handleAction(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
// do something with the request's context, like querying the db
db.getUser(ctx, userid)
// Everything is done and need to notify the user.
// However we lost the context for something like tracing, logging or timeout control
// since SendMessage doesn't accept `Context`
bot.SendMessage(chatId int64, text string, opts *SendMessageOpts)
}
Hope I made my point clear ๐
Hey hey! thanks for opening.
Yes, of course - that makes complete sense. Was wondering when someone would ask for this to be honest ๐
I'd be happy to to add WithContext (or even WithCtx if thats preferred? not sure what the go ecosystem trends to).
Just need to come up with a clean(ish) way of representing that without blindly duplicating the code; shouldn't be too difficult!
Let me know how #192 looks to you!
I'd really appreciate it if you could try out the branch on your side, and run any tests you might need - this would be a really helpful datapoint so I can make sure everything is working as expected (and is as intuitive as possible!)