Learning Golang Context!! Never Looked At It!

  Рет қаралды 42,495

TheVimeagen

TheVimeagen

Күн бұрын

Пікірлер: 42
@bennythetiger6052
@bennythetiger6052 11 ай бұрын
Started learning go a week ago as a experienced developer and boy oh boy do I already love it with all my heart. It's all so easyyy and simple and straight to the point
@mazharansari7813
@mazharansari7813 2 ай бұрын
It's Python but with compiler and blazzzinglyy fast.
@gauff3r
@gauff3r Жыл бұрын
Hey Prime, we would love more of your takes on advanced Go topics. Thank you for your hard work!
@Mikenight120
@Mikenight120 Жыл бұрын
Loving this Go content lately, adding all of them to downloads to binge watch 💯
@dv_xl
@dv_xl 11 ай бұрын
I find that context as a kv store tends to get messy when it's really common in a codebase. This has perf overhead (contexts are trees, and key lookups are traversals) but worse it can lead to hidden side effects if a function differs it behaviour based on contextual information. It can be a lifesaver if you need to have a globally accessible request scoped value, but use with caution.
@enzo.albornoz
@enzo.albornoz Жыл бұрын
Prime, ninja edition
@Kane0123
@Kane0123 11 ай бұрын
Will he update the thumbnails when he returns to normal… hmmm
@GoogleIsErratas
@GoogleIsErratas 11 ай бұрын
lol
@pookiepats
@pookiepats 2 ай бұрын
It looks terrible 😂
@bryanenglish7841
@bryanenglish7841 11 ай бұрын
Context is amazing. Watching you learn Go is super awesome, I’ve been with it for almost 10 years and it just now feels like Go is getting its due.
@gauravaws20
@gauravaws20 9 ай бұрын
bryan your videos are awesome too. i remember there was so little good go content a couple of years go and I stumbled on your videos. I was starting a new job and your videos helped me ramp up. thank you.
@QuantumMechanic343
@QuantumMechanic343 11 ай бұрын
Prime, using middleware to put things into a context is a super cool pattern. Let’s say you have the following route `/foo/:fooID/bar/:barID`. You could have a middleware package maintain a cache of the `foo` resource by its `fooID`. The middleware can pull the `fooID` from the path, and put the `foo` resource into the request context. This means that `bar`s handler doesn’t need to know the specifics of how to fetch `foo`, it just pulls it out of the context. If we add another route like `/foo/:fooID/grug/:grugID`, the ‘grug’ handler will also have access to the `foo` resource. As routes continue to be added under `foo`, you save yourself the trouble of putting in the boilerplate code to go fetch it.
@peteredmonds1712
@peteredmonds1712 11 ай бұрын
That's super interesting. Any code examples?
@ESPkenner48
@ESPkenner48 11 ай бұрын
I initially liked the approach, but mapping all values to `interface{}` within the context package of Go posed challenges due to its generic nature. To address this, I now define a struct with fields that are consistently required across different middleware handlers. This struct is passed as a parameter to handler functions, which improves type safety and enables syntax highlighting, making the code more maintainable. I remain open to other solutions that may be more efficient though.
@pookiepats
@pookiepats 2 ай бұрын
The foo bar crap is so useless, if you can’t express a use case in real world terms for your relative domain then you’re just yanking to syntax
@QuantumMechanic343
@QuantumMechanic343 2 ай бұрын
@ thanks for taking the time to share your thoughts. My example is trying to demonstrate how middleware and a context can be used to handle resource caching. I can see now that I’m making the assumption that the reader already knows something about resources on an HTTP server, and knows what resource caching is. To be fair to me, the comment was directed towards the creator of the video, who would be familiar with these concepts. In the example, `foo` and `bar` are generic names for resources, and the route structure suggests that each `foo` can own one or more `bar`. I can replace those words with something less generic though; let’s say we are working with multiple questions for a test, and that `foo` is a `question` and `bar` is a possible `answer` to that question. Let’s also say that our system also needs to support different types of questions (multiple choice, numeric input, etc), and that only multiple choice questions can have answers. This business rule means that if a user tries to add an answer to a question, we need server-side logic to reject the request. Let’s also say the operation to add a nee answer to a question involves a POST request to `/questions/:questionId/answers`, and that the body of the request would contain the answer. The request handler on the server would be able to use the request’s context to know the questionId, and the answer the user is trying to add to the question. In order to execute our business logic, the request handler needs to be able to use the questionId to determine if the question is of the multiple choice type. One way to solve this issue is to have a system that will return a question when given a questionId. Once implementation of this system could be a repository, which stores questions in a database and indexes them based on their the questionId. Another implementation would be to maintain a cache of questions indexed by their questionId in the server middleware. That middleware could then use the questionId in the request context to add the question to the context. That way, when the handler gets the request context it can now access the questionId, answer, as well as the question. From the handler’s point of view, this is all done without having to interface with any other system, and it doesn’t need to know how to fetch a question based on it’s questionId. This also means that other handlers that are under the `/questions` route do not need to have this knowledge as well! All of those handlers just get it from the context.
@maxpyte1119
@maxpyte1119 11 ай бұрын
C# (sorry for the curse word), as said earlier, has it as 2 separate concepts: CancellationToken and HttpContext 1)CT just basically passed inside of any async method, and internal method should manually check, when running continuous operation, is token revoked, and stop in this case. 2)HC is basically storage for all request-scoped data, e.g. user identity, headers, request and response data, and it's shared between chains of async called method (because async in c# works as a state machine, so diff. threads, that work on 1 chain, should somehow now, how to have contrxt of request)
@thiccbonkus
@thiccbonkus 11 ай бұрын
C# MENTIONED
@defeqel6537
@defeqel6537 11 ай бұрын
IIRC there is no propagation of cancellations in C# (except manual)
@christopher8641
@christopher8641 11 ай бұрын
17:28 real Dad moment showing through right there
@felixw841
@felixw841 10 ай бұрын
The cast can not blow up because it’s one with two assignments (There’s probably a proper name for this): the casted value and ok (bool indicating if the cast was successful). This is even mentioned in the comment above in the example code.
@SandraWantsCoke
@SandraWantsCoke 11 ай бұрын
I do a DB lookup of a user by his token and then I put all the necessary info into context (key, value) and use it across the functions which have access to the request. It's just something you share data across functions within one request. No different from a React context, where you share data across components.
@param6759
@param6759 11 ай бұрын
Love the learing with the Primeagen , would love to see more of this
@kevinkkirimii
@kevinkkirimii 11 ай бұрын
Children cannot cancel the parent but they can cancel their own children's context derived from them. I have seen open telemetry using context in a great way
@uby2007
@uby2007 11 ай бұрын
His hair is the same colour as the text string highlights. lol
@gabrielomane-yeboah
@gabrielomane-yeboah 11 ай бұрын
Prime's brain is transparent now
@frechjo
@frechjo 5 ай бұрын
So they made dynamic variables. Isn't that what that is about, petty much, just dynamic variables implemented by hand?
@Ujjaval___
@Ujjaval___ Жыл бұрын
we can see through your brain .😂😂
@Woodmastermc
@Woodmastermc 3 ай бұрын
Does anyone feel like Go is the spiritual successor to Perl? No? Just me . . . .okay. Thanks for the video Prime!
@pookiepats
@pookiepats 2 ай бұрын
Hell nah . Now there is a project called Go++ (compiles to Go) that would fit that description
@pollathajeeva23
@pollathajeeva23 Жыл бұрын
Gen this is similar to C#' ish Cancellation tokens.
@rpanda_old
@rpanda_old 10 ай бұрын
"vim is crap if you want it to be like vscode"
@spartan_j117
@spartan_j117 11 ай бұрын
How did he make the page display in dark mode?!
@su1cedek
@su1cedek 11 ай бұрын
DarkReader, probably
@dixztube
@dixztube 5 ай бұрын
Good video
@NiclasGleesborg
@NiclasGleesborg Жыл бұрын
Nice hair
@su1cedek
@su1cedek 11 ай бұрын
This talk explains context incredibly well imo: kzbin.info/www/bejne/o5fKc5t9qpqjmdE
@Stupendousboy
@Stupendousboy 11 ай бұрын
switchHairColorWithMustache()
@manolisbach2380
@manolisbach2380 3 ай бұрын
if you wanted js to be a backend language it would be terrble - node.js: am i a joke to you ? (yeah you are but anyway xD )
@TECHN01200
@TECHN01200 11 ай бұрын
Nice transparent hair.
@Kfoo-dj4md
@Kfoo-dj4md 11 ай бұрын
Probably can whip out a context like thing in Rust in an evening (I use Rust btw)
@int-64
@int-64 11 ай бұрын
balding
Golang is BAD for SMART PEOPLE
27:25
ThePrimeTime
Рет қаралды 297 М.
More Zig Learning
33:33
TheVimeagen
Рет қаралды 13 М.
Enceinte et en Bazard: Les Chroniques du Nettoyage ! 🚽✨
00:21
Two More French
Рет қаралды 42 МЛН
Сестра обхитрила!
00:17
Victoria Portfolio
Рет қаралды 958 М.
СИНИЙ ИНЕЙ УЖЕ ВЫШЕЛ!❄️
01:01
DO$HIK
Рет қаралды 3,3 МЛН
How To Use The Context Package In Golang?
17:03
Anthony GG
Рет қаралды 70 М.
First Realtime App With The Golang Platform
1:10:49
TheVimeagen
Рет қаралды 138 М.
Actix Web vs. Axum: Is One a Clear Winner?
8:59
OptiCode
Рет қаралды 3,7 М.
Level Up Your Golang: 5 Concepts You Need to know
19:22
Flo Woelki
Рет қаралды 17 М.
Golang Wish And Bubbletea at the same time
59:48
TheVimeagen
Рет қаралды 22 М.
HTMX + GO
1:16:33
TheVimeagen
Рет қаралды 64 М.
how can he be so good?
10:01
TheVimeagen
Рет қаралды 76 М.
Golang Context Package: It's More Than You Think!
8:26
Alex Mux
Рет қаралды 4,1 М.
Dependency Injection | Prime Reacts
28:34
ThePrimeTime
Рет қаралды 368 М.
My First Zig Interface
2:19:28
TheVimeagen
Рет қаралды 44 М.