Hi Yash, unfortunately that's the only approach at the moment.
Your request is very apropos of my thread, "Could we trade all the `ctx
context.Context` arguments for one pointer in `g`?". This is the exact
use case I have in mind. I believe it should be possible, and even a
fairly naïve implementation should not slow down code that does not use
the context variables at all.
I have a proposal in draft at: https://github.com/samv/go-context-proposal
Cheers,
Sam
On 3/1/24 12:40 AM, 'Yash Bansal' via golang-nuts wrote:
Hello,
I recently started writing code in Golang and wasn't aware that unlike
Java, we can't use ThreadLocals to propagate a context across the
code. It's mandatory to explicitly pass a context. I have already
written a service which is live in production now, however for
monitoring and other reasons, I need to pass the context argument to
every function.
*ASK *
Is there a tool or library which can help me do the same, instead of
me going to every function and it's caller and adding the context field?
I have been following this thread -
https://groups.google.com/g/golang-nuts/c/ti8M-fuu6RE/m/8w3LA1dXAwAJ
But looks like people in this thread have abandoned the idea of making
a library like this.
Any leads would be appreciated.
*::DISCLAIMER::
----------------------------------------------------------------------------------------------------------------------------------------------------
The contents of this e-mail and any attachments are confidential and
intended for the named recipient(s) only.E-mail transmission is not
guaranteed to be secure or error-free as information could be
intercepted, corrupted,lost, destroyed, arrive late or incomplete, or
may contain viruses in transmission. The e mail and its contents(with
or without referred errors) shall therefore notattach any liability on
the originator or redBus.com. Views or opinions, if any, presented in
this email are solely those of the author and may not necessarily
reflect the views or opinions of redBus.com. Any form of reproduction,
dissemination, copying, disclosure, modification,distribution and / or
publication of this message without the prior written consent of
authorized representative ofredbus. <http://redbus.in/>comis strictly
prohibited. If you have received this email in error please delete it
and notify the sender immediately.Before opening any email and/or
attachments, please check them for viruses and other defects.* --
You received this message because you are subscribed to the Google
Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/58b07900-05cf-4550-b069-96c6d4cc3614n%40googlegroups.com
<https://groups.google.com/d/msgid/golang-nuts/58b07900-05cf-4550-b069-96c6d4cc3614n%40googlegroups.com?utm_medium=email&utm_source=footer>.
--
Sam
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/391b89d1-aa88-4bb1-8253-89ee6a36647d%40vilain.net.