Learning Golang Context!! Never Looked At It!

  Рет қаралды 31,334

TheVimeagen

TheVimeagen

5 ай бұрын

LIVE ON TWITCH: / theprimeagen
Become a backend engineer. Its my favorite site
boot.dev/?promo=PRIMEYT
This is also the best way to support me is to support yourself becoming a better backend engineer.
Get in on Discord: / discord
Get in on Twitter: / theprimeagen
Got Something For Me to Read or Watch??:
/ theprimeagenreact

Пікірлер: 34
@gauff3r
@gauff3r 4 ай бұрын
Hey Prime, we would love more of your takes on advanced Go topics. Thank you for your hard work!
@bennythetiger6052
@bennythetiger6052 4 ай бұрын
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
@enzo.albornoz
@enzo.albornoz 4 ай бұрын
Prime, ninja edition
@Kane0123
@Kane0123 4 ай бұрын
Will he update the thumbnails when he returns to normal… hmmm
@GoogleIsErratas
@GoogleIsErratas 4 ай бұрын
lol
@Mikenight120
@Mikenight120 4 ай бұрын
Loving this Go content lately, adding all of them to downloads to binge watch 💯
@dv_xl
@dv_xl 4 ай бұрын
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.
@QuantumMechanic343
@QuantumMechanic343 4 ай бұрын
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 4 ай бұрын
That's super interesting. Any code examples?
@ESPkenner48
@ESPkenner48 4 ай бұрын
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.
@bryanenglish7841
@bryanenglish7841 4 ай бұрын
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 2 ай бұрын
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.
@param6759
@param6759 4 ай бұрын
Love the learing with the Primeagen , would love to see more of this
@christopher8641
@christopher8641 4 ай бұрын
17:28 real Dad moment showing through right there
@SandraWantsCoke
@SandraWantsCoke 4 ай бұрын
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.
@maxpyte1119
@maxpyte1119 4 ай бұрын
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 4 ай бұрын
C# MENTIONED
@defeqel6537
@defeqel6537 4 ай бұрын
IIRC there is no propagation of cancellations in C# (except manual)
@kevinkkirimii
@kevinkkirimii 4 ай бұрын
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
@gabrielomane-yeboah
@gabrielomane-yeboah 4 ай бұрын
Prime's brain is transparent now
@felixw841
@felixw841 3 ай бұрын
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.
@uby2007
@uby2007 4 ай бұрын
His hair is the same colour as the text string highlights. lol
@Ujjaval___
@Ujjaval___ 4 ай бұрын
we can see through your brain .😂😂
@Dyils
@Dyils 4 ай бұрын
Didn't think about the green screen when you got that hair, did you? :D
@pollathajeeva23
@pollathajeeva23 4 ай бұрын
Gen this is similar to C#' ish Cancellation tokens.
@rpanda_old
@rpanda_old 3 ай бұрын
"vim is crap if you want it to be like vscode"
@NiclasGleesborg
@NiclasGleesborg 4 ай бұрын
Nice hair
@spartan_j117
@spartan_j117 4 ай бұрын
How did he make the page display in dark mode?!
@su1cedek
@su1cedek 4 ай бұрын
DarkReader, probably
@Stupendousboy
@Stupendousboy 4 ай бұрын
switchHairColorWithMustache()
@TECHN01200
@TECHN01200 4 ай бұрын
Nice transparent hair.
@Kfoo-dj4md
@Kfoo-dj4md 4 ай бұрын
Probably can whip out a context like thing in Rust in an evening (I use Rust btw)
@su1cedek
@su1cedek 4 ай бұрын
This talk explains context incredibly well imo: kzfaq.info/get/bejne/o8yXdct42pvUk6M.html
@user-kw9cu
@user-kw9cu 4 ай бұрын
balding
SQLx vs SQLc
55:23
TheVimeagen
Рет қаралды 27 М.
Golang Wish And Bubbletea at the same time
59:48
TheVimeagen
Рет қаралды 18 М.
Luck Decides My Future Again 🍀🍀🍀 #katebrush #shorts
00:19
Kate Brush
Рет қаралды 8 МЛН
Final muy inesperado 🥹
00:48
Juan De Dios Pantoja
Рет қаралды 19 МЛН
3 wheeler new bike fitting
00:19
Ruhul Shorts
Рет қаралды 52 МЛН
HTMX + GO
1:16:33
TheVimeagen
Рет қаралды 62 М.
The Greatest TO DO App Ever Created | Prime Reacts
30:20
ThePrimeTime
Рет қаралды 131 М.
I AM SUCH A BAD PROGRAMMER
1:46:52
TheVimeagen
Рет қаралды 49 М.
Multi database schema changes
1:22
Turso
Рет қаралды 2,7 М.
THIS is the BEST Way to Write HTTP Services in Golang
13:53
JSON, TOML, YML? No! Apples New Config Lang!
29:19
ThePrimeTime
Рет қаралды 143 М.
Golang Building SSH and Bubble Tea App
57:08
TheVimeagen
Рет қаралды 62 М.
My Best Decision Professionally
5:40
ThePrimeagen
Рет қаралды 143 М.
Golang is BAD for SMART PEOPLE
27:25
ThePrimeTime
Рет қаралды 249 М.
Being An Efficient Developer | Prime Reacts
22:56
ThePrimeTime
Рет қаралды 148 М.
Main filter..
0:15
CikoYt
Рет қаралды 12 МЛН
Asus  VivoBook Винда за 8 часов!
1:00
Sergey Delaisy
Рет қаралды 1,1 МЛН
Best mobile of all time💥🗿 [Troll Face]
0:24
Special SHNTY 2.0
Рет қаралды 856 М.
YOTAPHONE 2 - СПУСТЯ 10 ЛЕТ
15:13
ЗЕ МАККЕРС
Рет қаралды 117 М.