Understanding Contexts in Go in 5(-ish?) Minutes
Вставка
- Опубліковано 22 сер 2024
- 👨💻 For the price of $7.99 every month, sign up and gain access to a growing list of premium courses on my site - tutorialedge.n...
Welcome Gophers, in this video, we'll be covering the topic of contexts within Go and how you an use them to propagate key/values through your application and also to handle things like timeouts. If you prefer, the original text version of this article can be found here - tutorialedge.n...
✅ Subscribe and hit that 🔔 to get notified for all the latest tutorials!
🤓 / elliot_f
💻 tutorialedge.net
🎥 Recording Setup
Microphone - amzn.to/3hvASys
Mic Boom - amzn.to/3o0cW8Q
Mouse - amzn.to/2WZMoZs
Monitor 1 - amzn.to/38IUlYy
Monitor 2 - amzn.to/3rBTZf7
Mount - amzn.to/3o3185V
USB-C Hub - amzn.to/3o2xRbw
I searched for tutorials about go's context and yours was the only one I understood. Thank you so much.
Nicely explained. I like how the video started with "what and why", and give a brief overview of the concept!
I want my $0.00001 from the ads back 😆. Great video, keep it up.
Finally understood this concept. Thank you so much.
So early it's still in 360p :) Great video!
Really well made video. Thank you.
Would you please cover the case of context use with grpc? Like how does the grpc lib make use of context, or how to use it for auth ...
your are my friend make my love golang, you are really great teacher, 😇🙂
Thank you for this. Quite explanatory! 🙏
good explanation. thanks.
Good explanation bro... ✔️
Great and simple, a side question, what is the theme you are using at VS code?
cobalt2 by wes bos
It's very helpful. Thank you so much for the effort.
Thank You. The tutorial is great!
thank you for the very good explanation 😀
Definitely removed some of the confusion!
something that caused a little bit of confusion to me: the `
Yeah this is no need for a select here :)
A question 10:40 is there need for the select case at line 35 since ctx.done() blocks and will be invoked once the timeout has exceeded ?!
Great example, thanks a lot for the info :D
I've always wondered if sending information or adding logic via context is not a kind of hidden dependency in my code. Some people consider it a bad practice.
It is, and it shouldn't be used at all, according to Google.
@@klarnorbert A citation would be great.
Good explination.
Thank you Peter! I hope you are keeping well!
Can you share your emacs config?
This audio is not clear. would be great if you can add subtitles
Wouldn’t it make sense to pass context by pointer?
If go is copying by value, shouldn’t ctx.done lose reference to the outer scope
i kinda understand context. though still not so clear.
This is one part of go I really don't get. It hides dependencies inside a super parameter. If your method needs to know something it should be explicit or in scope of the struct as a base config. Putting values into a dictionary and passing the dictionary around hides the dependency. I don't understand how this became used in Go at all as it is actually an anti-pattern.
I think there's a bit of a misunderstanding about the intent of context.Context here. You absolutely should not use it for things that are needed by the function, but the context may be used to pass extraneous information such as the request_id or trace_id that's currently being handled so that you can enrich logs/traces without polluting your function's logic and making it overly complex.
If there are hard dependencies needed by your functions or methods, then these should be either passed in, or set on the struct that the method hangs off of.
@@Tutorialedge I'm not sure how timeouts/deadlines fit into the "not needed by the function" category. Seems like critical functionality that functions should need to handle. For example, if you time out in the middle of a function that updates 2 different data sources with related information (let's say, a database entry that points to a file storage URL), the function would need to react to a timeout or this would result in data inconsistency.
広めてください」、
Video is only 360p, too blurry.
All good now, youtube took longer than it used to.
I don't think this should be part of the Go language.
This is basically the go community on everything.
it took you 8 minutes to get to the context interface despite this being a tutorial on contexts in Go ...